check if location is activated on startup
This commit is contained in:
parent
ec8d3d466b
commit
ef8c5e9039
@ -23,10 +23,10 @@ class _HomePageState extends State<HomeView> {
|
||||
bool locationEnabled = false;
|
||||
|
||||
Future<LatLng?> getLatLng() async {
|
||||
LocationPermission permissionStatus = await Geolocator.checkPermission();
|
||||
if (permissionStatus == LocationPermission.denied) {
|
||||
permissionStatus = await Geolocator.requestPermission();
|
||||
if (permissionStatus == LocationPermission.denied || permissionStatus == LocationPermission.deniedForever) {
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied || permission == LocationPermission.deniedForever) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -48,6 +48,16 @@ class _HomePageState extends State<HomeView> {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
Geolocator.checkPermission().then((permission) => setState(() {
|
||||
locationEnabled = permission != LocationPermission.denied && permission != LocationPermission.deniedForever;
|
||||
}));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
Reference in New Issue
Block a user