You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
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.");
}
}
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
getCurrentPosition();
},
child: Text('Get Location'),
),
),
);
}
}
The text was updated successfully, but these errors were encountered: