Flutter PopScope的无法拦截返回

783 阅读1分钟

设置了PopScope( canPop: false,不能拦截物理返回键

解决方案 包裹一个MaterialApp即可

GetBuilder<MainController>( builder: (_) {
return 
 MaterialApp(
  home: PopScope(
    canPop: false,
    onPopInvoked:(didPop) async {
          await FlutterBackToDeskPlugin.backToDesktop() ;
    },
child: Scaffold( 
  appBar: null, 
  bottomNavigationBar: Theme( data: ThemeData( splashColor: Colors.transparent, highlightColor:   Colors.transparent, ), 
  child: CustomBottomNavigationBar( backgroundColor: const Color(0xff202021), type:      BottomNavigationBarType.fixed, currentIndex: controller.currentIndex, items: controller.bottomTabs, onTap: (index) { controller.currentIndex = index; controller.update(); }, ), ), 
  body: IndexedStack( index: controller.currentIndex, children: controller.pages, ), ), ); }, ))