FlutterBluePlus

repository·master·Indexed 21 days ago

https://github.com/chipweinberger/flutter_blue_plus

A Bluetooth Low Energy (BLE) plugin for Flutter designed for the BLE Central Role. It provides cross-platform support for iOS, macOS, Android, Linux, and Web. The plugin uses an endorsed federated architecture with platform-specific implementations (flutter_blue_plus_android, flutter_blue_plus_darwin, flutter_blue_plus_linux, and flutter_blue_plus_web). It does not support Bluetooth Classic, the BLE Peripheral Role, or iOS iBeacons.

Tokens
21K
Snippets
64
Records
105
Agent score
73%

What's inside flutter_blue_plus

  1. Understand FlutterBluePlus capabilities and limitations

    master

    FlutterBluePlus is a Bluetooth Low Energy (BLE) plugin for Flutter that supports the BLE Central Role.

    Key Limitations:

    • No Bluetooth Classic support: Devices like Arduino HC-05/HC-06, speakers, headphones, mice, keyboards, and gamepads are not supported as they use Bluetooth Classic.
    • No BLE Peripheral Role: If your application needs to act as a BLE Peripheral, use FlutterBlePeripheral or bluetooth_low_energy instead.
    • iOS iBeacons: iBeacons are not supported on iOS via this plugin; Apple requires the use of CoreLocation for beacon functionality.

    Supported Platforms:

    • iOS, macOS, Android, Linux, and Web.
  2. Understand FlutterBluePlus license conditions and telemetry

    master

    All users of FlutterBluePlus must adhere to the following common conditions:

    1. Source Code Redistributions: Redistributions of source code must retain the original copyright notice and the entire license text without modification.
    2. Relicensing Prohibition: The software may not be relicensed under different terms.
    3. Build-Time License Ping: The software may attempt to send limited license telemetry at build time. This includes the package name, app name, app version, FlutterBluePlus version, and date. This telemetry does not include source code or end-user data. Failure to send this telemetry does not prevent the software from being used or built.
    4. Endorsement Restriction (Open Use only): For personal, nonprofit, or educational use, the names of the copyright holder or contributors may not be used to endorse or promote derived products without prior written permission.
  3. Common conditions and build-time telemetry

    master

    All users of FlutterBluePlus must adhere to these common conditions:

    1. Source Code Redistributions: Redistributions of source code must retain the original copyright notice and the entire license text without modification.
    2. Relicensing Prohibition: The software may not be relicensed under different terms.
    3. Build-Time License Ping: The software may attempt to send limited license telemetry at build time. This includes the package name, app name, app version, FlutterBluePlus version, and date. This does not include source code or end-user data. Failure to send this telemetry does not prevent building or using the software.
    4. BSD-3 Compliance: Some portions of the codebase remain under the BSD-3 license. It is advised to follow the BSD-3 conditions described in NOTICE.md to remain compliant with those specific contributors.
  4. Connect to a Bluetooth device

    master

    Use device.connect() to establish a connection.

    Key considerations:

    • Disconnection: Listen to device.connectionState to handle disconnections. When a device disconnects, you must re-discover services before attempting to communicate again.
    • Cleanup: Use device.cancelWhenDisconnected(subscription, ...) to automatically clean up listeners when the device disconnects. Use delayed: true to ensure the disconnected event is actually received by your listener.
    • Auto Connect: If you use autoConnect: true, the connect() method returns immediately. You must listen to device.connectionState to know when the connection actually occurs. Note that autoConnect is incompatible with the mtu argument; if you need a specific MTU, call requestMtu() manually after connecting.
    // listen for disconnection
    var subscription = device.connectionState.listen((BluetoothConnectionState state) async {
        if (state == BluetoothConnectionState.disconnected) {
            print("${device.disconnectReason?.code} ${device.disconnectReason?.description}");
        }
    });
    
    // cleanup: cancel subscription when disconnected
    device.cancelWhenDisconnected(subscription, delayed:true, next:true);
    
    // Connect to the device
    await device.connect();
    
    // Disconnect from device
    await device.disconnect();