从 FlutterViewController 弹回到原生 iOS 应用程序

Anu*_*man 5 ios swift flutter

我将 flutter 模块添加到现有的 iOS 应用程序中。目前,为了进行测试,我展示了FlutterViewController提前FlutterEngineAppDelegate. 尽管颤动屏幕正确显示,但我无法返回本机 iOS 应用程序。

谷歌搜索显示这SystemNavigator.pop()可以完成工作,但它对我不起作用,因为它在这里这里提到。如何返回我的本机 iOS 应用程序?

我显示颤动屏幕的快速侧代码如下所示

@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)
    }
Run Code Online (Sandbox Code Playgroud)

我的 Flutter 侧代码弹出回本机 iOS 应用程序看起来像这样,但不起作用。

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),
      ),
Run Code Online (Sandbox Code Playgroud)

如果我替换SystemNavigator.pop()Navigator.of(context).pop()也不起作用并显示黑屏,这是有道理的,因为它没有任何后备路线。据我了解,这并没有弹出屏幕,而是关闭了整个 flutter 应用程序。是不是?我该如何解决这个问题?

小智 -1

exit(0)当平台是 iOS 时尝试,不知何故SystemNavigator.pop()不起作用。整个代码如下:

onPressed: () {
  if(Platform.isIOS) {
    Navigator.pop(context);
    exit(0);
  } else {
    SystemNavigator.pop(animated: true);
  }
},
Run Code Online (Sandbox Code Playgroud)