bluetooth_low_energy 3.0.0-dev.4 copy "bluetooth_low_energy: ^3.0.0-dev.4" to clipboard
bluetooth_low_energy: ^3.0.0-dev.4 copied to clipboard

A Flutter plugin for controlling the bluetooth low energy.

bluetooth_low_energy #

A Flutter plugin for controlling the bluetooth low energy.

Features #

CentralManager #

  • Set up the central manager.
  • Get/Listen the state of the central manager.
  • Start/Stop discovery.
  • Connect/Disconnect peripherals.
  • Get maximum write length of peripherals.
  • Read RSSI of peripherals.
  • Discover GATT.
  • Get GATT services.
  • Get GATT characteristics.
  • Get GATT descriptors.
  • Read/Write/Notify GATT characteristics.
  • Read/Write GATT descriptors.

PeripheralManager #

  • Set up the peripheral manager.
  • Get/Listen the state of the peripheral manager.
  • Add/Remove/Clear service(s).
  • Start/Stop advertising.
  • Get maximum write length of centrals.
  • Listen read/write/notify characteristic requests from centrals.
  • Send read/write characteristic replies to centrals.
  • Notify characteristic value changed to centrals.

Getting Started #

Add bluetooth_low_energy as a dependency in your pubspec.yaml file.

dependencies:
  bluetooth_low_energy: ^<latest-version>

Remember to call await CentralController.setUp() before use any apis of this plugin.

Note: Bluetooth Low Energy doesn't work on emulators, so use physical devices which has bluetooth features for development.

Android #

Make sure you have a miniSdkVersion with 21 or higher in your android/app/build.gradle file.

Note: Don't call getMaximumWriteLength immediately when connected to a peripheral after Android 13, the onMtuChanged callback maybe called with connection events after Android 13, and getMaximumWriteLength will call requestMtu will also triggered onMtuChanged, if you called this before the connection onMtuChanged, you will get a fake completion and cause all methods you called before the real onMtuChanged triggered will never complete!

iOS and macOS #

According to Apple's documents, you must include the NSBluetoothAlwaysUsageDescription on or after iOS 13, and include the NSBluetoothPeripheralUsageDescription key before iOS 13.

The PeripheralManager#startAdvertising only support name and serviceUUIDs, see the startAdvertising document

Linux #

Not tested enough, if you occured any problems, file an issue to let me know about it, i will fix it as soon as possible.

PeripheralManager api is not supported because the bluez plugin doesn't support this yet, see How to use bluez to act as bluetooth peripheral

Windows #

Not implemented yet but maybe someday or someone can use the win32 api to implement this plugin_interface or someday the flutter team support C# on windows platform or someday I am familiar with C++ language...