Monday, 27 May 2019

Open native UIViewController in Flutter

I have an application I develop in Flutter, and it has one UIViewController that has to be implemented in native IOS (there is no other workaround, it is a must)

I have implemented it, it works according to the first tests, but I'd like to double check if it is okkey by your opinion, as I am not so experienced in Flutter, and I am afraid a bit a make some mess in my app navigation stack that can cause bugs in the future.

So, I have implemented it by MethodChannel. I have a method, that called from 'Flutter side'. I don't paste my MethodChannel related things here, as they are trivial.

In my AppDelegate didFinishLaunchingWithOptions I added this:

let flutterViewController = FlutterViewController()
    self.navigationController = UINavigationController(rootViewController: flutterViewController)
    self.navigationController?.isNavigationBarHidden = true

    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window.rootViewController = self.navigationController
    self.window.makeKeyAndVisible()

And my open method like this:

private func openNativeUI(result: FlutterResult) {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let uiController = sb.instantiateViewController(withIdentifier: "nativeui")

        self.navigationController?.pushViewController(uiController, animated: true)

        result(true)
    }

What do you think?

Any advise is highly appreciated and thank you for your help in advance!



from Open native UIViewController in Flutter

No comments:

Post a Comment