selector

Flutter AppBar 返回键监听

2019-06-27  本文已影响0人  奋斗的小蜗牛yyl

使用WillPopScope

@override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          appBar: AppBar(
            title: Text('WillPopScope'),
            centerTitle: true,
          ),
        ),
        onWillPop: ()=>_willPop());
  }
Future<bool> _willPop () { //返回值必须是Future<bool>
      Navigator.pop(context);
    return Future.value(false); 
  }

详细代码flutter_github

简书代码https://www.jianshu.com/p/fb8916599cec

上一篇 下一篇

猜你喜欢

热点阅读