Im very new to flutter, I have splash screen were loading will finish once the connection to the API success, after that I need to navigate to the next page, I want to check if the permission of the location was granted then go to home page, otherwise go to the page where the user need to click on a button to get the current location I don't know how to do this but the step of checking API connection was done, now the second step of checking the location, here is my code
Future<dynamic> getCurrentLocationData() async {
final status = await Permission.locationWhenInUse.status;
if (status == PermissionStatus.granted) {
return status;
} else if (status == PermissionStatus.denied) {
return status;
} else if (status == PermissionStatus.permanentlyDenied) {
return status;
}
}
Splash screen:
void loadData() {
_con.progress.addListener(() {
double progress = 0;
_con.progress.value.values.forEach((_progress) {
progress = _progress;
});
if (progress == 100) {
try {
//here need to check if the location permission was granted so go to the next page
Navigator.of(context).pushNamed('/homepage');
} catch (e) {}
}
});
}
CodePudding user response:
if the user click on permission deny, you cannot regenerate permission popup to ask the permissios, else you can route the user to app setting inside Application Manager to allow required permissions...
Although you can check whether the user has previously marked the permission Allow or Deny.
Create the function that check for permission status and call it in initState method.
@override
void initState() {
checkPermissionStatus();
super.initState();
}
void checkPermissionStatus() async{
var status = await Permission.locationWhenInUse.status;
if (status != PermissionStatus.granted) {
//show Dialog or route to specific page (or route to Application Manager)
}else{
// Go to Second Screen
}
}