Skip to content

Instantly share code, notes, and snippets.

@bistole
Created December 11, 2020 17:57
Show Gist options
  • Select an option

  • Save bistole/ea3da9c879de2985577b32c7cd44d54c to your computer and use it in GitHub Desktop.

Select an option

Save bistole/ea3da9c879de2985577b32c7cd44d54c to your computer and use it in GitHub Desktop.
receive event from flutter
class Commands : NSObject {
let COMMANDS = "/COMMANDS";
let CMD_OPEN_DIALOG = "CMD:OPEN_DIALOG";
weak var binaryMessager : FlutterBinaryMessenger?
var methodChannel : FlutterMethodChannel?
func methodInvoked(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void {
NSLog(call.method);
switch(call.method) {
case self.CMD_OPEN_DIALOG:
let dict = call.arguments as! Dictionary<String, String>;
let dialog = OpenDialog()
dialog.openFileDialog(
title: dict["title"] ?? "Import Files",
fileTypes: dict["types"] ?? "*",
result: result);
break;
default:
result(FlutterMethodNotImplemented);
}
}
func register(withBinaryMessager bm: FlutterBinaryMessenger) {
// save binary messager
binaryMessager = bm;
// create a method channel
let channelName = (Bundle.main.infoDictionary?["CFBundleIdentifier"] as! String) + COMMANDS
methodChannel = FlutterMethodChannel.init(name: channelName, binaryMessenger: binaryMessager!)
methodChannel?.setMethodCallHandler(self.methodInvoked(call:result:));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment