Hi as I wrote in the title how can I achieve this? I've got the location permission but can not turn the location on!
6 Answers
It will open setting. so user can enable it. it is best practice as per my knowledge.
Install plugin :
https://pub.dartlang.org/packages/android_intent#-installing-tab-
Import in your dart :
import 'package:android_intent/android_intent.dart';
Add method :
void openLocationSetting() async {
final AndroidIntent intent = new AndroidIntent(
action: 'android.settings.LOCATION_SOURCE_SETTINGS',
);
await intent.launch();
}
Invoke it done...

- 4,638
- 2
- 33
- 52
-
2What about IOS? – Himanshu Jan 24 '20 at 08:01
-
This is not working for me. Nothing show at all on android 6.0. – Scorb Feb 09 '21 at 17:54
-
How to get state ON or OFF? Instead of calling screen? – Kostadin Jan 13 '22 at 12:46
I'll be using the things I learnt from this link to guide you.
Add this dependency to pubspec.yaml
dependencies:
location: ^3.0.0
Now, import the following package to your .dart
file
import 'package:location/location.dart';
Now inside a function, to ask for the user's location using a pop-up box, you can do-
Location location = new Location();
bool _serviceEnabled;
LocationData _locationData;
The above were the declarations that we will be using in our following code -
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
debugPrint('Location Denied once');
}
}
Now, you can use the above snippet as per your requirement to make Location request calls using a pop-up for whatever number of times you want.
If the user's locations has been granted, you can use the following line to store and use the location data.
_locationData = await location.getLocation();
If the location is not granted, then the above line would result in the program failing, so be sure to only use the above line when the user has allowed location access from the pop-up.
Hope this helps. Cheers!

- 381
- 3
- 7
flutterlocation Plugin shows you the dialogue to turn on gps as like native android

- 3,562
- 7
- 24
- 43
First add this dependency in pubspec.yaml:
location: ^1.4.0
Then, use this function to retrieve current location of your device:
import 'package:location/location.dart';
fetchCurrentLocation() async {
print("STARTING LOCATION SERVICE");
var location = Location();
location.changeSettings(accuracy: LocationAccuracy.POWERSAVE,interval: 1000,distanceFilter: 500);
if (!await location.hasPermission()) {
await location.requestPermission();
}
try {
await location.onLocationChanged().listen((LocationData currentLocation) {
print(currentLocation.latitude);
print(currentLocation.longitude);
latitude = currentLocation.latitude;
longitude = currentLocation.longitude;
});
} on PlatformException {
location = null;
}
}

- 11
- 2
- 14

- 2,410
- 3
- 19
- 30
-
5Actually, I'm using this dependency to get the location but it does not get the permissions so I do it manually by simple-permissions. if I turn off the location this code goes into catch block without asking anything to turn on the location or getting permissions! – Moein Hosseini Aug 29 '18 at 04:39
-
1@Rachit Rawat : your an give lat and long but question how to enable gps or location service in android ? – Khurshid Ansari Dec 18 '18 at 11:18
-
The question is to Ask for ON/OFF GPS.....not for how to get location..... – Himanshu Jan 29 '20 at 11:32
I did the same but sometimes pop-up notification of location permission doesn't appear.
I add these lines in the following location:
project/android/app/src/main/AndroidManifest.xml

- 3,969
- 8
- 38
- 49

- 99
- 1
- 5