Flutter app needs to check if Bluetooth and Location enabled

4,259

Solution 1

I hope this still would be useful

You can check if bluetooth is enabled with:

Future<bool> _checkDeviceBluetoothIsOn() async {
    return await flutterBlue.isOn;
  }

and check if location is enabled using PermissionHandler package with:

Future<bool> _checkDeviceLocationIsOn() async {
    return await Permission.locationWhenInUse.serviceStatus.isEnabled;
  }

Solution 2

I'm working on the same case as you actually, and the way i check for it is to use the following:

For checking bluetooth activation, you can listen to the state stream provided by the flutter blue library, you can access it like the following :

FlutterBlue.instance.state 

For location, i did not found a "native fluttery way" to do it, so i'm using the geolocator package which gives you the ability to check if the locaiton is active.

It provides you with a future that resolve to a boolean saying true for active, and false for disabled.

Geolocator().isLocationServiceEnabled()
Share:
4,259
Nick Letwin
Author by

Nick Letwin

Updated on December 16, 2022

Comments

  • Nick Letwin
    Nick Letwin over 1 year

    I'm working with a Flutter app, using a Dart package called flutter_blue to connect to a Bluetooth device. The Bluetooth device connects successfully, but only if the user has Bluetooth and Location enabled on their device. I'm trying to find a way to detect whether Location and Bluetooth is enabled on the device before trying to connect so that I can prompt the user to turn them on. Currently, I'm also using a Dart package that works with native Android intents to bring up the settings menus for each (also working). I just need a way to check if they're enabled so that I know whether to show the settings menus for users to enable them.