ios - 从 FlutterViewController 弹回原生 iOS 应用
问题描述
我将颤振模块添加到我现有的 iOS 应用程序中。目前为了测试,我正在展示一个FlutterViewController
提前FlutterEngine
在AppDelegate
. 虽然颤动屏幕正确出现,但我无法回到原生 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)
}
我的 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),
),
如果我用它替换SystemNavigator.pop()
它Navigator.of(context).pop()
也不起作用并显示黑屏,这是有道理的,因为它没有任何后备路线。据我了解,这并没有弹出屏幕,而是关闭了整个颤振应用程序。是不是?我该如何解决这个问题?
解决方案
exit(0)
当平台是 iOS 时尝试,不知何故SystemNavigator.pop()
不起作用。整个代码如下:
onPressed: () {
if(Platform.isIOS) {
Navigator.pop(context);
exit(0);
} else {
SystemNavigator.pop(animated: true);
}
},
推荐阅读
- spring-mvc - 带参数的百里香片段
- sql - Query 正在 Impala 上工作,但不在 hive 上
- arrays - 有没有办法转换 UnsafeMutablePointer
到 UnsafeMutablePointer ? - javascript - 获取无效日期时输入的日期值
- typescript - TypeGraphql 和 Prisma 2 类型冲突
- typescript - 如何正确声明以下打字稿接口/类型?
- python - Pandas Python - 根据多个条件提取行。包括数据示例
- drupal - 扩展 ControllerBase 和依赖注入的 Drupal 8 控制器
- html - HTML 5 在 flexbox 中使用画布会导致奇怪的缩放
- microsoft-graph-api - Microsoft Graph 支持编辑打开的 PowerPoint 文件