From 3bad0d550182a62bb1665e1e211b54eb0459f40c Mon Sep 17 00:00:00 2001 From: wurong <953969641@qq.com> Date: Wed, 28 Aug 2024 15:29:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=E8=AE=BE=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=8A=B6=E6=80=81=E5=BC=82=E5=B8=B8=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/setting/permission_setting_page.dart | 28 +++++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/setting/permission_setting_page.dart b/lib/setting/permission_setting_page.dart index a4ea4ff5..575634ad 100644 --- a/lib/setting/permission_setting_page.dart +++ b/lib/setting/permission_setting_page.dart @@ -15,14 +15,20 @@ class PermissionSettingPage extends StatefulWidget { } } -class _PermissionSettingPage extends State { +class _PermissionSettingPage extends State with WidgetsBindingObserver { @override void initState() { super.initState(); - + WidgetsBinding.instance.addObserver(this); queryPermission(); } + @override + void dispose() { + super.dispose(); + WidgetsBinding.instance.removeObserver(this); + } + List title = [ S.current.dingwei, S.current.tongzhi, @@ -75,14 +81,24 @@ class _PermissionSettingPage extends State { ]; queryPermission() async { - await permissions.forEach((element) async { - if (await element.isGranted) { - permissionSwitch[element] = true; + for(var it in permissions){ + if (await it.isGranted) { + permissionSwitch[it] = true; } - }); + } setState(() {}); } + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (state == AppLifecycleState.resumed) { + // 处理应用程序切换回前台的逻辑 + queryPermission(); + } else if (state == AppLifecycleState.paused) { + // 处理应用程序切换到后台的逻辑 + } + } + @override Widget build(BuildContext context) { return Scaffold(