How to pass data from flutter to native iOS (Swift) by using platform specific code. I searched in the internet and stack overflow but it is showing an example of only Native Android. Below is the code till now what i have tried
Dart code
static const methodChannel = MethodChannel('com.ios');
void openPaymentMethod() async {
String? result = await methodChannel
.invokeMethod<String>('isSetUpAvailable', {'text': hello});
if (result != null) {
print(result);
}
}
Native Swift code
let METHOD_CHANNEL_NAME = "com.ios"
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
let methodChannel = FlutterMethodChannel(name: METHOD_CHANNEL_NAME, binaryMessenger: controller.binaryMessenger)
methodChannel.setMethodCallHandler({
(call:FlutterMethodCall,result: @escaping FlutterResult) -> Void in
switch call.method{
case "isSetUpAvailable":
result("Success")
default:
result(FlutterMethodNotImplemented)
}
})