bluetooth_enable 0.1.1
bluetooth_enable: ^0.1.1 copied to clipboard

Flutter plugin to turn on bluetooth within app (Android only)

Introduction #

BluetoothEnable is a Bluetooth plugin for Flutter, to programtically request turning on Bluetooth within applications.

This plugin was created with the intention to allow developers to customise their own application workflow on when permissions are requested.

This plugin is supported only for Android.

Usage #

Enable Bluetooth #

import 'package:bluetooth_enable/bluetooth_enable.dart';

// Request to turn on Bluetooth within an app
BluetoothEnable.enableBluetooth.then((value){
  if (result == "true"){
    //Bluetooth has been enabled
  }
  else if (result == "false") {
    //Bluetooth has not been enabled
  }
});

Enable Bluetooth with Custom Alert #

This method calls an alert from Dart level. Depending on the user's selection, Bluetooth will either be manually turned on without an additional dialog request or nothing happens.

ParameterDescription
contextThe material context of your current content
dialogTitleThe title of the dialog is displayed in a large font at the top
displayDialogContentEnable or disable showing dialog content
dialogContentThe content of the dialog that is displayed in the center
cancelBtnTextThe cancel button text of the dialog (left button)
acceptBtnTextThe accept button text of the dialog (right button)
dialogRadiusThe border radius of dialog
barrierDismissibleEnable or Disable whether dialog is dismissible on external click
import  'package:bluetooth_enable/bluetooth_enable.dart';

Future<void> customEnableBT(BuildContext context) async {
  String dialogTitle = "Hey! Please give me permission to use Bluetooth!";
  bool displayDialogContent = true;
  String dialogContent = "This app requires Bluetooth to connect to device.";
  //or
  // bool displayDialogContent = false;
  // String dialogContent = "";
  String cancelBtnText = "Nope";
  String acceptBtnText = "Sure";
  double dialogRadius = 10.0;
  bool barrierDismissible = true; //

  BluetoothEnable.customBluetoothRequest(context, dialogTitle, displayDialogContent, dialogContent, cancelBtnText, acceptBtnText, dialogRadius, barrierDismissible).then((result) {
    if (result == "true"){
      //Bluetooth has been enabled
    }
  });
}
10
likes
90
pub points
87%
popularity

Publisher

Unknown

Flutter plugin to turn on bluetooth within app (Android only)

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on bluetooth_enable