flutter中手机系统自带返回事件触发判断

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);
}
posted @ 2022-06-14 18:19  Mizuki-Vone  阅读(427)  评论(0)    收藏  举报