我想在用户返回上一页之前展示一个 AdWords 插页式广告。按下返回按钮时如何执行此操作?
最佳答案
我认为您可以使用 WillPopScope
小部件。您可以传递一个回调函数,该函数将在 View 即将弹出时调用。只需在 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)
希望有帮助!
https://stackoverflow.com/questions/49079580/
相关文章:
firebase - 如何在 Flutter 中从 Firebase Auth 获取用户 ID?
flutter - 流生成器。错误状态 : Stream has already been list
dart - 在 Dart 中向服务器发出多个独立请求的最佳方式
image - Flutter CircleAvatar backgroundImage没有填满圆圈
flutter - 如何在 flutter 中为折叠元素设置动画
flutter - 控制和禁用 flutter 中的下拉按钮?
android - 如何设置 Flutter 应用的构建和版本号