How can I "push" a UIViewController from FlutterViewController

In Swift, We can open native iOS viewController from a flutter action event using the method channel, In flutter, you need to add the following lines to trigger the native iOS method. Add these lines in your action method

var platform = const MethodChannel('navigation');
final String result = await platform.invokeMethod('IOS');

In iOS, add the following lines in the AppDelegate application method.

let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let methodChannel = FlutterMethodChannel(name: "navigation", binaryMessenger:controller.binaryMessenger)
navigationController = UINavigationController(rootViewController: controller)
navigationController.setNavigationBarHidden(true, animated: false)
self.window!.rootViewController = navigationController
self.window!.makeKeyAndVisible()
methodChannel.setMethodCallHandler({
    (call: FlutterMethodCall, result: @escaping FlutterResult) -> 
    Void in
if call.method == "IOS" {
      let vc = "Your viewController"(nibName: "Your 
      viewController", bundle: nil)
      navigationController.pushViewController(vc, animated: 
     false)
} else {
         result(FlutterMethodNotImplemented)
         return
}
})

Native view controller back button action.

self.navigationController?.popViewController(animated: true)

Thank you.


In Swift, We can open native iOS viewController from a flutter action event using the method channel,

  • In flutter, you need to add the following lines to trigger the native iOS method. Add these lines in your action method
var platform = const MethodChannel('com.nativeActivity/iosChannel');
final String result = await platform.invokeMethod('StartNativeIOS');
  • In iOS, add the following lines in the AppDelegate application method
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController

let methodChannel = FlutterMethodChannel(name: "com.nativeActivity/iosChannel", binaryMessenger:controller.binaryMessenger)

methodChannel.setMethodCallHandler({
  (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
        
  if call.method == "StartNativeIOS" {
    let mainVC = MainViewController() // Your viewController
    let navigationController = UINavigationController(rootViewController: mainVC)
    self.window.rootViewController = navigationController
    self.window.makeKeyAndVisible()
  } else {
    result(FlutterMethodNotImplemented)
    return
  }
})

It will work! cheers

Note: But there is no going back to the flutter view.

So here is the proper way of doing it. Flutter Navigation Using Coordinator Pattern