如何访问Flutter Back按钮功能?
问题内容:
在用户返回上一页之前,我想展示一个AdWords非页内广告。按下返回按钮时该怎么办?
问题答案:
我认为您可以利用WillPopScope
小部件。您可以传递一个回调函数,当视图关于pop时将调用该函数。只需执行弹出之前要完成的所有任务,然后返回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)
希望有帮助!