A simple Flutter plugin for turning on and off Bluetooth on Android devices.
import 'package:bluetoothonoff/bluetoothonoff.dart';
BluetoothOnOff.turnOnBluetooth;
BluetoothOnOff.turnOffBluetooth;
Since turnOnBluetooth and turnOffBluetooth both return a Future<bool>
you can await them. So as shown in the example you can use the bool for checking if the invocation was successful.
bool success = false;
success = await BluetoothOnOff.turnOnBluetooth;
Because Bluetooth emulation is not supported by AVD you need to run your Flutter project on a physical device.
Currently only Android is supported.
Check the console. If the plugin fails to turn on or off Bluetooth it will print a string containing any of the following self explanatory PlatformExceptions:
- Bluetooth was already on/off.
- Android version lower than 4.4 (KitKat) is unsupported.
- Could not turn on/off " Bluetooth. (something went wrong on the Android OS side)