Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native Dialog for location setting on Flutter

Tags:

flutter

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?

enter image description here

Expanded View of dialog:

enter image description here

like image 605
VipiN Negi Avatar asked Nov 22 '19 13:11

VipiN Negi


People also ask

How do I open location settings in android programmatically?

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.

How to get the user’s current location in flutter?

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.

What is dialog in flutter?

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 ...

Is it possible to implement geolocation in flutter?

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:

How to use location background mode on Android in flutter?

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.


Video Answer


1 Answers

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();
}
like image 75
VipiN Negi Avatar answered Nov 11 '22 05:11

VipiN Negi