Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter - How to turn on or ask user to turn the location on?

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!

like image 984
Moein Hosseini Avatar asked Aug 28 '18 14:08

Moein Hosseini


People also ask

How do I ask to turn on location in flutter?

Method 1: Location Setting Popup within AppAdd this package by adding the following lines in your pubspec. yaml file. This code will show the following alert dialog within App. If the user presses the "OK" button, the GPS will get turned ON.

How do you get location access on flutter?

To use the Geolocator plugin on the web you need to be using Flutter 1.20 or higher. Flutter will automatically add the endorsed geolocator_web package to your application when you add the geolocator: ^6.2. 0 dependency to your pubspec.


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

like image 117
Khurshid Ansari Avatar answered Oct 10 '22 10:10

Khurshid Ansari