Flutter - 从导航栏更改后退按钮

Flutter - Change back button from Navigation Bar

美好的一天,

我需要更改 Android 手机导航栏上的后退按钮的命令,如下图所示?

我需要更改按钮以显示一条消息,"Do you really want to quit the application?"。确认用户离开程序。

有人可以帮忙吗?

谢谢。

使用 WillPopScope 小部件处理后退按钮操作,示例:

  class TestingWidget extends StatefulWidget {

    @override
    TestingWidgetState createState() {
      return new TestingWidgetState();
    }
  }

  class TestingWidgetState extends State<TestingWidget> {
    Future<bool> _onBackPressed(){
      final alertDialog = AlertDialog(
        content: Text("Do you really want to quit the application?"),
        actions: <Widget>[
          FlatButton(
            child: Text('Yes'),
            onPressed: () => Navigator.of(context).pop(),
          ),
          FlatButton(
            child: Text('No'),
            onPressed: () => Navigator.of(context).pop(),
          )
        ],
      );
      showDialog(
          barrierDismissible: false,
          context: context,
          builder: (context) => alertDialog);
    }

    @override
    Widget build(BuildContext context) {
      return WillPopScope(
        onWillPop: _onBackPressed,
        child: Scaffold(
          appBar: AppBar(),
          body: Center(child: Text("Hello world"),),
        ),
      );
    }
  }