Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecated geolocator dependancy #36

Open
NGURE-TIM opened this issue Feb 7, 2023 · 0 comments
Open

deprecated geolocator dependancy #36

NGURE-TIM opened this issue Feb 7, 2023 · 0 comments

Comments

@NGURE-TIM
Copy link

in the tutorial the code didnt work for me so i used this instead import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
class LoadingScreen extends StatefulWidget {
@OverRide
_LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State {
Future getCurrentPosition() async {
// Check if the location service is enabled
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
print("Location service enabled: $serviceEnabled");
if (!serviceEnabled) {
return Future.error("Location service is not enabled.");
}

// Check if the location permission is granted
LocationPermission status = await Geolocator.checkPermission();
print("Location permission: $status");
if (status == LocationPermission.denied) {
  // Request the location permission
  status = await Geolocator.requestPermission();
  if (status == LocationPermission.denied) {
    // Permission is not granted, return an error message
    return Future.error("Location permission not granted.");
  }
}

// Get the current position if the location permission is granted
Position position = await Geolocator.getCurrentPosition(
    desiredAccuracy: LocationAccuracy.high);

print(position);
return position;

}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
getCurrentPosition();
},
child: Text('Get Location'),
),
),
);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant