美文网首页selector
Flutter AppBar 返回键监听

Flutter AppBar 返回键监听

作者: 奋斗的小蜗牛yyl | 来源:发表于2019-06-27 14:19 被阅读0次

使用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

相关文章

网友评论

    本文标题:Flutter AppBar 返回键监听

    本文链接:https://www.haomeiwen.com/subject/mnfrcctx.html