如何在flutter Android应用程序中退出应用程序之前按主页和最近按钮时显示警报

问题描述 投票:0回答:1

我需要的是,当用户单击主页和最近按钮时,第一个警报必须出现“您想退出应用程序吗”,然后再次点击必须关闭应用程序

我尝试使用应用程序生命周期,但无法正常工作

android flutter mobile
1个回答
0
投票

您可以使用

PopScope
来完成。您可以使用
canPop
来阻止系统后退手势。

如果需要,您还可以使用

onPopInvoked
参数。

要使用

PopScope
,只需用它包裹您的小部件并显示AlertDialog:

PopScope(
     canPop: false,
     onPopInvoked: (bool didPop) {},
     child: TextButton(),
),

有关

PopScope
的更多信息,您可以在此处查看文档:PopScope

© www.soinside.com 2019 - 2024. All rights reserved.