简体   繁体   English

如何在 Flutter MaterialApp 中检测 iOS 向后滑动手势?

[英]How to detect iOS back swipe gesture in Flutter MaterialApp?

I want to detect when the user uses the back swipe gesture in my iOS App.我想检测用户何时在我的 iOS 应用程序中使用向后滑动手势。 How can I do it?我该怎么做?

I created CupertinoPageRoute hoping that it would somehow work with it...我创建了 CupertinoPageRoute,希望它能以某种方式与它一起工作......

    return MaterialApp(
        initialRoute: AllProductsScreen.id,

        onGenerateRoute: (RouteSettings settings) {
          switch (settings.name) {
            case AllProductsScreen.id:
              return CupertinoPageRoute(
                  builder: (_) => AllProductsScreen(), settings: settings);
            case ProductScreen.id:
              return CupertinoPageRoute(
                  builder: (_) => ProductScreen(), settings: settings);
            case FavoritesScreen.id:
              return CupertinoPageRoute(
                  builder: (_) => FavoritesScreen(), settings: settings);
            default:
              return CupertinoPageRoute(
                  builder: (_) => AllProductsScreen(), settings: settings);
          }
        },
      );

You can use onWillPop from cupertino_will_pop_scope library.您可以使用onWillPop库中的onWillPop

@override
Widget build(BuildContext context) {
  return ConditionalWillPopScope(
    child: _MyScreenContent(),
    onWillPop: _onWillPop,
    shouldAddCallbacks: _hasChanges,
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM