Is there a way to implement a Dialog for Location setting like the image below which gets triggered when app requires GPS location and doesn't find. Hitting OK will right away turn on the system GPS. This seems more convenient for users instead of taking them to location and manually turn on. Is it possible to implement such thing in Flutter?
Expanded View of dialog:
Programmatically we can turn on GPS in two ways. First, redirect the user to location settings of a device (by code) or another way is to ask to turn on GPS by GPS dialog using LocationSettingsRequest and SettingsClient.
Using the Flutter Location plugin, it’s effortless to get the user’s location on Android and iOS devices. In this article, we’ll show how to get the user’s current location and display the address. We will also implement a demo using the location package. This plugin for Flutter handles getting location on Android and iOS.
Flutter – Dialogs. The dialog is a type of widget which comes on the window or the screen which contains any critical information or can ask for any decision. When a dialog box is popped up the all the other functions get disabled until you close the dialog box or provide an answer. We use a dialog box for a different type of condition such as ...
This is not the same with Flutter though — it has a lot of amazing packages that abstract that boilerplate code out for you and makes implementing geolocations a dream. Another bright side is that you get the functionality on both Android and iOS. Let’s take a quick look at what we are building today to gather location data:
If your project was created before Flutter 1.12, you might need to follow this. To use location background mode on Android, you have to use the enableBackgroundMode ( {bool enable}) API before accessing location in the background and adding necessary permissions.
Credits to Rajesh, as answered here. The plugin lets you add this native dialog for a quick location setting.
The implementation is quite simple as this:
import 'package:location/location.dart';
var location = Location();
Future _checkGps() async {
if(!await location.serviceEnabled()){
location.requestService();
}
}
@override
void initState() {
super.initState();
_checkGps();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With