Function 如何访问“颤振后退”按钮功能?

Function 如何访问“颤振后退”按钮功能?,function,dart,flutter,Function,Dart,Flutter,在用户返回上一页之前,我想提交一份AdWords填空。当按下返回按钮时,我该如何执行此操作?我认为您可以使用widget。您可以传递一个回调函数,当视图关于pop时将调用该函数。只需在pop之前完成任何任务,然后返回true 例如: Future<bool> _willPopCallback() async { // await showDialog or Show add banners or whatever // then return true; //

在用户返回上一页之前,我想提交一份AdWords填空。当按下返回按钮时,我该如何执行此操作?

我认为您可以使用widget。您可以传递一个回调函数,当视图关于pop时将调用该函数。只需在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)
Future\u willPopCallback()异步{
//等待showDialog或Show添加横幅或其他内容
//然后
return true;//如果要弹出路由,则返回true
}
//然后将回调传递给WillPopScope
新建WillPopScope(子级:new Scaffold(),onWillPop:\u willPopCallback)

希望有帮助

在使用WillPopScope时,有没有办法保持“刷到弹出”功能?当我添加它时,我的停止工作。我试图使用它,这样当有人滑动弹出,键盘将关闭,但我还没有弄清楚。我用平移手势尝试了它,但这在任何地方都有效,但在滑动到弹出的边缘除外。参数类型“Future”不能分配给参数类型“Future Function()”。我想你正在进行函数调用
\u willPopCallback()
,只需使用
\u willPopCallback