如何访问 Flutter 后退按钮功能?

How to access Flutter Back button functionality?

我想在用户 return 到上一页之前展示一个 AdWords 插页式广告。当 return 按钮被按下时我该怎么做?

我认为您可以使用 WillPopScope 小部件。您可以传递一个回调函数,该函数将在视图弹出时调用。随便做 pop 之前要完成的任务然后 return true.

示例:

Future<bool> _willPopCallback() async {
    // await showDialog or Show add banners or whatever
    // then
    return true; // return true if the route to be popped
}


//then pass the callback to WillPopScope
new WillPopScope(child: new Scaffold(), onWillPop: _willPopCallback)

希望对您有所帮助!