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(