I want to display custom window with text before an user allows location sharing, when user denies to share location, I want to log him out. However I am having problem in this method, after pressing deny it doesn't proceed to the Navigator push unless I log out and login again then it keeps pushing me all the time to the login screen whenever I try to log in. How can I set this up properly?
What I want to achieve: https://www.youtube.com/shorts/PnJi98a2LDI
User logs in, the dialog appears, press OK, gets asked for location sharing, if he presses deny -> log him out.
If he logs in back again, prompt the window again.
If user has accepted location sharing, let him inside app and not push to login screen.
_serviceEnabled = await _location.serviceEnabled();
if (!_serviceEnabled) {
print("service disabled");
_serviceEnabled = await _location.requestService();
print("requesting service");
if (!_serviceEnabled) {
}
}
print(_serviceEnabled);
_permissionGranted = await _location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await _location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
print("not granted");
Navigator.pushNamed(context, '/login');
}
}
await _location.getLocation();
if(_permissionGranted == PermissionStatus.denied)
AlertDialog(
title: const Text('Disclaimer'),
content: SingleChildScrollView(
child: ListBody(
children: const <Widget>[
Text('This is app collects location data.'),
],
),
),
actions: [
TextButton(
child: const Text('OK'),
onPressed: () {
},
),
],
),