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;
|
bool locationEnabled = false;
|
||||||
|
|
||||||
Future<LatLng?> getLatLng() async {
|
Future<LatLng?> getLatLng() async {
|
||||||
LocationPermission permissionStatus = await Geolocator.checkPermission();
|
LocationPermission permission = await Geolocator.checkPermission();
|
||||||
if (permissionStatus == LocationPermission.denied) {
|
if (permission == LocationPermission.denied) {
|
||||||
permissionStatus = await Geolocator.requestPermission();
|
permission = await Geolocator.requestPermission();
|
||||||
if (permissionStatus == LocationPermission.denied || permissionStatus == LocationPermission.deniedForever) {
|
if (permission == LocationPermission.denied || permission == LocationPermission.deniedForever) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,6 +48,16 @@ class _HomePageState extends State<HomeView> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
Geolocator.checkPermission().then((permission) => setState(() {
|
||||||
|
locationEnabled = permission != LocationPermission.denied && permission != LocationPermission.deniedForever;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
Reference in New Issue
Block a user