问题
I'm building an application where I use platform channel of flutter to navigate to iOS native. There I change the rootViewController of the app to a native TabViewController. When the user clicks back I want to navigate back to flutter but the app freezes. Is there a safe way to do this?
I have tried saving the state of the flutterViewController before change and handing it back when the user presses back.
this code is for the flutter side to navigate to the native iOS view.
var result = await AppConstant.channel_iOS.invokeMethod(AppConstant.method_open_sermon_player);
if(result != null && result[AppConstant.key_restart_ui])
{
RestartWidget.restartApp(context);
}
print(result);
}
this is for the native iOS side to receive the control of the app from flutter.
let flutterChannel = FlutterMethodChannel.init(name: "iOS", binaryMessenger: flutterViewController);
flutterChannel.setMethodCallHandler { (flutterMethodCall, flutterResult) in
if flutterMethodCall.method == "openSermonPlayer" {
UIView.animate(withDuration: 0.5, animations: {
self.window?.rootViewController = nil
let viewToPush = PlayerTabViewController()
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.makeKeyAndVisible()
self.window.rootViewController = viewToPush
})
if CheckIfPlaying.sharedInstance.quitSermon == true {
CheckIfPlaying.sharedInstance.quitSermon = false
let result = ["restart_ui": self.switchBack()]
flutterResult(result)
}
}
I expect the app to change its rootViewController to flutter and keep on working but it just freezes on that view.
来源:https://stackoverflow.com/questions/57889520/how-to-change-the-root-view-controller-back-to-flutter-from-native-ios