flutter 如何禁止左滑返回?

有些页面不想左滑返回上一个页面如何禁止?
我知道一种方法如下,在有的页面能有效果在有的页面不行,不知道为啥,请问有别的禁止办法吗?

Scaffold(
         body: WillPopScope(
           onWillPop: () async {
             return false;
           },
           child: 
阅读 4.1k
1 个回答
home: WillPopScope(
  onWillPop: () async {
    return false;
  },
  child: Scaffold(
    body: _pageList[currentIndex],
    bottomNavigationBar: BottomNavigationBar(
      onTap: (int index) {
        setState(() {
          currentIndex = index;
        });
      },
    ),
  ),
),
MaterialApp(
  initialRoute: '/',
  routes: {
    '/': (context) => WillPopScope(
      onWillPop: () async => false,
      child: MyHomePage(),
    ),
  },
);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题