我需要的是,当用户单击主页和最近按钮时,第一个警报必须出现“您想退出应用程序吗”,然后再次点击必须关闭应用程序
我尝试使用应用程序生命周期,但无法正常工作
您可以使用
PopScope
来完成。您可以使用 canPop
来阻止系统后退手势。
如果需要,您还可以使用
onPopInvoked
参数。
要使用
PopScope
,只需用它包裹您的小部件并显示AlertDialog:
PopScope(
canPop: false,
onPopInvoked: (bool didPop) {},
child: TextButton(),
),
有关
PopScope
的更多信息,您可以在此处查看文档:PopScope