Created
December 11, 2020 17:57
-
-
Save bistole/ea3da9c879de2985577b32c7cd44d54c to your computer and use it in GitHub Desktop.
receive event from flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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