【发布时间】:2020-06-05 06:38:25
【问题描述】:
我正在使用以下代码将用户导航到设置屏幕以手动允许位置权限:
PermissionHandler().openAppSettings();
一旦用户允许此权限,我将检查该权限是否被授予。如果获得批准,我将允许用户导航到下一个屏幕。
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
checkPermission(); //this will check the status of permission when the user returns back from the settings page.
}
checkPermission() async {
var location = Location();
bool _permission = false;
bool serviceStatus = await location.serviceEnabled();
if (serviceStatus) {
print("enable");
_permission = await location.requestPermission();
print("Permission result: $_permission");
if (_permission) {
// Navigate to next screen
}else{
print("permission not enable");
}
} else {
print("not enable");
}
}
问题是didChangeAppLifecycleState 方法总是被屏幕上的任何操作调用。当用户从后台导航到应用程序或从设置屏幕导航到屏幕时,我应该如何检测状态。
以下是状态,但没有一个有用。
resumed-
inActivate pauseddetached
【问题讨论】:
-
在调用 didChangeAppLifecycleState 时检查 AppLifeCycleState,它可以是非活动的、暂停的、恢复的、分离的。 api.flutter.dev/flutter/dart-ui/AppLifecycleState-class.html
-
@Karthik 谢谢你的回复。 ApplifecycleState.resume 被调用。但是如果我也关闭位置对话框,这个单位总是被调用。我真正想要检测的是检测背景到前景动作的特定方法或标志