Pop Back to Native iOS App from FlutterViewController

Viewed 872

I added flutter module into my existing iOS app. Currently for testing I am showing a FlutterViewController with ahead of time created FlutterEngine in AppDelegate. Though the flutter screen comes up correctly I am not able to come back to the native iOS app.

Little googling showed that SystemNavigator.pop() will do the work but it is not working for me as it is mentioned here and here. How can I go back to my native iOS app ?

My swift side code to show the flutter screen looks like this

@objc func showFlutter() {
      let flutterEngine = (UIApplication.shared.delegate as! AppDelegate).flutterEngine
      let flutterViewController =
          FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
        flutterViewController.modalPresentationStyle = .fullScreen
      present(flutterViewController, animated: true, completion: nil)
    }

My Flutter side code to pop back to the native iOS app looks like this which is not working.

appBar: AppBar(
        leading: new IconButton(
          icon: new Icon(Icons.arrow_back, color: Colors.white),
          onPressed: () => SystemNavigator.pop(),
        ),
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),

If I replace SystemNavigator.pop() with Navigator.of(context).pop() it does not work either and shows a black screen which makes sense as it does not have any fallback route. This is not popping out Screen as much as I understand, it is closing the whole flutter app. Is not it? How can I solve this?

1 Answers

try exit(0) when platform is iOS , somehow SystemNavigator.pop() does not work. whole code as below:

onPressed: () {
  if(Platform.isIOS) {
    Navigator.pop(context);
    exit(0);
  } else {
    SystemNavigator.pop(animated: true);
  }
},
Related