To use Swift's FlutterMethodChannel without flutterViewController, you can follow these steps:
let engine = FlutterEngine(name: "my_engine")
engine.run();
guard let flutterChannel = FlutterMethodChannel(name: "my_channel", binaryMessenger: engine.binaryMessenger) else {
return
}
func myMethod(arguments: Any?) -> String? {
// Code to execute
return "Result of my method"
}
flutterChannel.setMethodCallHandler { [weak self] (call: FlutterMethodCall, result: FlutterResult) in
guard call.method == "myMethod" else {
result(FlutterMethodNotImplemented)
return
}
let arguments = call.arguments
let response = self?.myMethod(arguments: arguments)
result(response)
}
With these steps, you should be able to use Swift's FlutterMethodChannel without the need for flutterViewController.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-07 12:53:03 +0000
Seen: 11 times
Last updated: Jul 07 '23
How to add a custom button in SwiftUI for iOS13 that enables going back between screens?
How can the update of properties from both ParentViewModel and ChildViewModel in SwiftUI be solved?
Can SwiftUI be utilized to restrict the touch region for a drag gesture?
How can the color of a selected element (Picker) be modified in SwiftUI for WatchOS?
How to make a calendar layout that is horizontal using Swiftui?
What is the process to add a radio button with a check mark on a TableView cell using Swift?
How to limit UITextField input to only accept numerical values?