WillPopScope组件
用WillPopScope包裹根页面组件
WillPopScope(
onWillPop: _requestPop,
child: pageContainer()
)
其中onWillPop绑定的函数就是系统返回事件触发后的处理函数
Future<bool> _requestPop() async { // 调用原生返回,返回原生页面,根据自身场景自己定义处理函数 const platform = MethodChannel("flutterBackNative"); try { final int res = await platform.invokeMethod("flutterBackNative"); } on PlatformException catch (e) { print(e); } return Future.value(false); }