gpt4 book ai didi

flutter - 在Flutter中,将整个应用程序包装在WillPopScope中时,不会调用onWillPop

转载 作者:行者123 更新时间:2023-12-03 04:40:01 24 4
gpt4 key购买 nike

当在Android上按返回按钮时,该应用将被杀死。我希望我的整个应用程序具有按下后退按钮的功能,用户会收到通知要求确认。如果他们确认,则最小化该应用程序。因此,我尝试将整个“MaterialApp”作为一个 child 包装在“WillPopScope”中。但是,不会触发“onWillPop”。

void main() async {
runApp(
WillPopScope(
child: MaterialApp(
title: 'Test',
home: Frame(),
),
onWillPop: () async {
print('will pop!!!!!!!!!');
return false;
},
),
);
}

最佳答案

您不应该以此来包围整个应用程序。您应该使用要在其上运行该功能的每页小部件。用脚手架围住页面

关于flutter - 在Flutter中,将整个应用程序包装在WillPopScope中时,不会调用onWillPop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63407684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com