Bluetooth plugin for Flutter

Overview

pub package Chat


FlutterBlue



Introduction

FlutterBlue is a bluetooth plugin for Flutter, a new app SDK to help developers build modern multi-platform apps.

Alpha version

This library is actively developed alongside production apps, and the API will evolve as we continue our way to version 1.0.

Please be fully prepared to deal with breaking changes. This package must be tested on a real device.

Having trouble adapting to the latest API? I'd love to hear your use-case, please contact me.

Cross-Platform Bluetooth LE

FlutterBlue aims to offer the most from both platforms (iOS and Android).

Using the FlutterBlue instance, you can scan for and connect to nearby devices (BluetoothDevice). Once connected to a device, the BluetoothDevice object can discover services (BluetoothService), characteristics (BluetoothCharacteristic), and descriptors (BluetoothDescriptor). The BluetoothDevice object is then used to directly interact with characteristics and descriptors.

Usage

Obtain an instance

FlutterBlue flutterBlue = FlutterBlue.instance;

Scan for devices

// Start scanning
flutterBlue.startScan(timeout: Duration(seconds: 4));

// Listen to scan results
var subscription = flutterBlue.scanResults.listen((results) {
    // do something with scan results
    for (ScanResult r in results) {
        print('${r.device.name} found! rssi: ${r.rssi}');
    }
});

// Stop scanning
flutterBlue.stopScan();

Connect to a device

// Connect to the device
await device.connect();

// Disconnect from device
device.disconnect();

Discover services

List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
    // do something with service
});

Read and write characteristics

// Reads all characteristics
var characteristics = service.characteristics;
for(BluetoothCharacteristic c in characteristics) {
    List<int> value = await c.read();
    print(value);
}

// Writes to a characteristic
await c.write([0x12, 0x34])

Read and write descriptors

// Reads all descriptors
var descriptors = characteristic.descriptors;
for(BluetoothDescriptor d in descriptors) {
    List<int> value = await d.read();
    print(value);
}

// Writes to a descriptor
await d.write([0x12, 0x34])

Set notifications and listen to changes

await characteristic.setNotifyValue(true);
characteristic.value.listen((value) {
    // do something with new value
});

Read the MTU and request larger size

final mtu = await device.mtu.first;
await device.requestMtu(512);

Note that iOS will not allow requests of MTU size, and will always try to negotiate the highest possible MTU (iOS supports up to MTU size 185)

Getting Started

Change the minSdkVersion for Android

Flutter_blue is compatible only from version 19 of Android SDK so you should change this in android/app/build.gradle:

Android {
  defaultConfig {
     minSdkVersion: 19

Add permissions for Bluetooth

We need to add the permission to use Bluetooth and access location:

Android

In the android/app/src/main/AndroidManifest.xml let’s add:

	 <uses-permission android:name="android.permission.BLUETOOTH" />  
	 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />  
	 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>  
 <application

IOS

In the ios/Runner/Info.plist let’s add:

	<dict>  
	    <key>NSBluetoothAlwaysUsageDescription</key>  
	    <string>Need BLE permission</string>  
	    <key>NSBluetoothPeripheralUsageDescription</key>  
	    <string>Need BLE permission</string>  
	    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>  
	    <string>Need Location permission</string>  
	    <key>NSLocationAlwaysUsageDescription</key>  
	    <string>Need Location permission</string>  
	    <key>NSLocationWhenInUseUsageDescription</key>  
	    <string>Need Location permission</string>

For location permissions on iOS see more at: https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services

Reference

FlutterBlue API

Android iOS Description
scan Starts a scan for Bluetooth Low Energy devices.
state Stream of state changes for the Bluetooth Adapter.
isAvailable Checks whether the device supports Bluetooth.
isOn Checks if Bluetooth functionality is turned on.

BluetoothDevice API

Android iOS Description
connect Establishes a connection to the device.
disconnect Cancels an active or pending connection to the device.
discoverServices Discovers services offered by the remote device as well as their characteristics and descriptors.
services Gets a list of services. Requires that discoverServices() has completed.
state Stream of state changes for the Bluetooth Device.
mtu Stream of mtu size changes.
requestMtu Request to change the MTU for the device.

BluetoothCharacteristic API

Android iOS Description
read Retrieves the value of the characteristic.
write Writes the value of the characteristic.
setNotifyValue Sets notifications or indications on the characteristic.
value Stream of characteristic's value when changed.

BluetoothDescriptor API

Android iOS Description
read Retrieves the value of the descriptor.
write Writes the value of the descriptor.

Troubleshooting

When I scan using a service UUID filter, it doesn't find any devices.

Make sure the device is advertising which service UUID's it supports. This is found in the advertisement packet as UUID 16 bit complete list or UUID 128 bit complete list.

Comments
  • Getting multiple ( duplicate ) characteristics Notification data  in Flutter_Blue 0.6

    Getting multiple ( duplicate ) characteristics Notification data in Flutter_Blue 0.6

    In 0.6 v with Flutter 1.7.8 , following issue observed

    • On app restart, successfully connected to the device with set notification = true on a characteristics
    • after disconnecting ble communication from device got 'disconnect' event in notification listener myDevice.state.listen((deviceState) { ..... });
    • without resetting the app , if again connected to the device with set notification = true on characteristics Then it is observed that we get duplicate notification value always. (read_characteristics.value.listen((){.......})
    • This duplication increases if we repeat the above steps ( without resetting app ) e.g. if we connect to device 5 times without resetting app then get 10 times duplicate data every time. This happens on debug as well as release apk

    Please let us know how to handle this issue? what is the way to handle disconnect event to avoid duplicate notifications?

    Thanks , Gaurav

    opened by GauravPatni 51
  • error: package androidx.core.app does not exist

    error: package androidx.core.app does not exist

    Since the 0.6.3 update, i have this error message and i can't build my app :

    /home/***/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_blue-0.6.3/android/src/main/java/com/pauldemarco/flutter_blue/FlutterBluePlugin.java:43: error: package androidx.core.app does not exist import androidx.core.app.ActivityCompat;

    opened by Jbz797 37
  • Is this repository dead?

    Is this repository dead?

    I've seem that the latest update on pub site was on october 2019 and here in git it has about 40+ pull requests. Most of them with no response from maintainers.

    Is that repository dead?

    If yes, can I suggest to transfer it's ownership?

    opened by shinayser 20
  • Issue with writeCharacteristic()

    Issue with writeCharacteristic()

    I am trying to connect to an Adafruit nrf8001 hooked up to an Arduino. It uses the UART service with the UUID 6E400001-B5A3-F393-E0A9-E50E24DCCA9E as defined here. I communicates with the TX and RX characteristics. I can connect to the device perfectly fine, but when I try to write to the TX characteristic, I get the error:

    D/FlutterBluePlugin(20492): [onCharacteristicWrite] uuid: 6e400002-b5a3-f393-e0a9-e50e24dcca9e status: 128
    E/flutter (20492): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Exception: Failed to write the characteristic
    E/flutter (20492): #0      BluetoothDevice.writeCharacteristic.<anonymous closure> 
        ../…/src/bluetooth_device.dart:132
    ... full output below
    

    I set up my scanning for devices with:

    setState(() {
      _scanning = true;
    });
    _scanSubscription =
      flutterBlue.scan(timeout: Duration(minutes: 1)).listen((scanResult) {
        if (scanResult.advertisementData.connectable) {
          setState(() {
            scanResults[scanResult.device.id] = scanResult;
          });
        }
      }, onDone: _cancelScanning);
    

    and then I connect with:

    setState(() {
      _deviceConnection = flutterBlue.connect(device).listen((s) {
        if (s == BluetoothDeviceState.connected) {
          print('Connected');
          setState(() {
            _device = device;
            _connected = true;
            _statusMessage = 'Connected to Cycler';
          });
          _cancelScanning();
          _discoverServices();
        } else {
          print('Not Connected');
          print(s.toString());
        }
      });
    });
    

    I then find the UART service and related characteristics as follows:

    _discoverServices() {
      setState(() {
        _statusMessage = 'Discovering device services';
      });
      _device.discoverServices().then((s) {
        setState(() {
          _statusMessage = 'Services discovered';
          _deviceServices = s;
        });
        _findUART();
      });
    }
    
    _findUART() {
      if (_deviceServices != null && _deviceServices.isNotEmpty) {
        _deviceServices.forEach((service) {
          //servicesList.add(Text(service.uuid.toString()));
          if (service.uuid.toString().toLowerCase() ==
              '6E400001-B5A3-F393-E0A9-E50E24DCCA9E'.toLowerCase()) {
            print('UART found');
            _uartService = service;
            service.characteristics.forEach((c) {
              if (c.uuid.toString().toLowerCase() ==
                  '6E400002-B5A3-F393-E0A9-E50E24DCCA9E'.toLowerCase()) {
                _tx = c;
                print('TX found');
              } else if (c.uuid.toString().toLowerCase() ==
                  '6E400003-B5A3-F393-E0A9-E50E24DCCA9E'.toLowerCase()) {
                _rx = c;
                print('RX found');
              }
            });
          }
        });
      }
    }
    

    Then I have a button onPressed: linked to the method _sendTest

    _sendTest() async {
      final value = await _device.writeCharacteristic(_tx, [0x12, 0x34],
          type: CharacteristicWriteType.withResponse);
      print(value);
    }
    

    Using Flutter 1.2.1. Running on Samsung Galaxy S8. Please let me know if you need any more relevant information.

    Here's the full error:

    E/flutter (20492): #0      BluetoothDevice.writeCharacteristic.<anonymous closure> 
    ../…/src/bluetooth_device.dart:132
    E/flutter (20492): #1      _rootRunUnary (dart:async/zone.dart:1132:38)
    E/flutter (20492): #2      _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    E/flutter (20492): #3      _FutureListener.handleValue (dart:async/future_impl.dart:126:18)
    E/flutter (20492): #4      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:639:45)
    E/flutter (20492): #5      Future._propagateToListeners (dart:async/future_impl.dart:668:32)
    E/flutter (20492): #6      Future._complete (dart:async/future_impl.dart:473:7)
    E/flutter (20492): #7      _cancelAndValue (dart:async/stream_pipe.dart:63:12)
    E/flutter (20492): #8      Stream.first.<anonymous closure> (dart:async/stream.dart:1170:11)
    E/flutter (20492): #9      _rootRunUnary (dart:async/zone.dart:1132:38)
    E/flutter (20492): #10     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    E/flutter (20492): #11     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
    E/flutter (20492): #12     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
    E/flutter (20492): #13     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
    E/flutter (20492): #14     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
    E/flutter (20492): #15     _WhereStream._handleData (dart:async/stream_pipe.dart:207:12)
    E/flutter (20492): #16     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
    E/flutter (20492): #17     _rootRunUnary (dart:async/zone.dart:1132:38)
    E/flutter (20492): #18     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    E/flutter (20492): #19     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
    E/flutter (20492): #20     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
    E/flutter (20492): #21     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
    E/flutter (20492): #22     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
    E/flutter (20492): #23     _MapStream._handleData (dart:async/stream_pipe.dart:232:10)
    E/flutter (20492): #24     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
    E/flutter (20492): #25     _rootRunUnary (dart:async/zone.dart:1132:38)
    E/flutter (20492): #26     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    E/flutter (20492): #27     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
    E/flutter (20492): #28     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
    E/flutter (20492): #29     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
    E/flutter (20492): #30     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
    E/flutter (20492): #31     _MapStream._handleData (dart:async/stream_pipe.dart:232:10)
    E/flutter (20492): #32     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
    E/flutter (20492): #33     _rootRunUnary (dart:async/zone.dart:1132:38)
    E/flutter (20492): #34     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    E/flutter (20492): #35     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
    E/flutter (20492): #36     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
    E/flutter (20492): #37     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:263:7)
    E/flutter (20492): #38     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:132:11)
    E/flutter (20492): #39     _WhereStream._handleData (dart:async/stream_pipe.dart:207:12)
    E/flutter (20492): #40     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:164:13)
    E/flutter (20492): #41     _rootRunUnary (dart:async/zone.dart:1132:38)
    E/flutter (20492): #42     _CustomZone.runUnary (dart:async/zone.dart:1029:19)
    E/flutter (20492): #43     _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
    E/flutter (20492): #44     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
    E/flutter (20492): #45     _DelayedData.perform (dart:async/stream_impl.dart:591:14)
    E/flutter (20492): #46     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
    E/flutter (20492): #47     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
    E/flutter (20492): #48     _rootRun (dart:async/zone.dart:1120:38)
    E/flutter (20492): #49     _CustomZone.run (dart:async/zone.dart:1021:19)
    E/flutter (20492): #50     _CustomZone.runGuarded (dart:async/zone.dart:923:7)
    E/flutter (20492): #51     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
    E/flutter (20492): #52     _rootRun (dart:async/zone.dart:1124:13)
    E/flutter (20492): #53     _CustomZone.run (dart:async/zone.dart:1021:19)
    E/flutter (20492): #54     _CustomZone.runGuarded (dart:async/zone.dar
    
    opened by BradHacker 19
  • Installation failed on osx

    Installation failed on osx

    On installation I get the following message and the installation fails. The protoc compiler is not found...

    ** /Users/satyajits/dev/flutter/bluetooth_example/Pods/!ProtoCompiler/protoc --objc_out=gen --proto_path=../protos ../protos/*.proto**

    However, the correct path is /Users/satyajits/dev/flutter/bluetooth_example/ios/Pods/!ProtoCompiler/protoc

    The difference is that the installation happens inside the ios folder of the flutter directory but somehow it is looking in the parent directory.

    Launching lib/main.dart on iPhone X in debug mode... Warning: CocoaPods recommended version 1.5.0 or greater not installed. Pods handling may fail on some projects involving plugins. To upgrade: brew upgrade cocoapods pod setup

    Running pod install... CocoaPods' output: ↳ Preparing

    Analyzing dependencies
    
    Inspecting targets to integrate
      Using `ARCHS` setting to build architectures of target `Pods-Runner`: (``)
    
    Fetching external sources
    -> Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
    -> Fetching podspec for `flutter_blue` from `.symlinks/plugins/flutter_blue/ios`
    
    Resolving dependencies of `Podfile`
    
    Comparing resolved specification to the sandbox manifest
      A !ProtoCompiler
      A Flutter
      A Protobuf
      A flutter_blue
    
    Downloading dependencies
    
    -> Installing !ProtoCompiler (3.5.0)
      > Copying !ProtoCompiler from `/Users/satyajits/Library/Caches/CocoaPods/Pods/Release/!ProtoCompiler/3.5.0-3e9dc` to `Pods/!ProtoCompiler`
    
    -> Installing Flutter (1.0.0)
    
    -> Installing Protobuf (3.6.0)
      > Copying Protobuf from `/Users/satyajits/Library/Caches/CocoaPods/Pods/Release/Protobuf/3.6.0-0fc0a` to `Pods/Protobuf`
    
    -> Installing flutter_blue (0.0.1)
     > Running prepare command
       $ /bin/bash -c  set -e mkdir -p gen /Users/satyajits/dev/flutter/bluetooth_example/Pods/!ProtoCompiler/protoc         --objc_out=gen         --proto_path=../protos         ../protos/*.proto
    [!] /bin/bash -c 
    set -e
    mkdir -p gen
    /Users/satyajits/dev/flutter/bluetooth_example/Pods/!ProtoCompiler/protoc         --objc_out=gen         --proto_path=../protos         ../protos/*.proto
    
    /bin/bash: line 3: /Users/satyajits/dev/flutter/bluetooth_example/Pods/!ProtoCompiler/protoc: No such file or directory
    
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/executable.rb:69:in `execute_command'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/executable.rb:27:in `block in executable'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer/pod_source_preparer.rb:66:in `block (2 levels) in run_prepare_command'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer/pod_source_preparer.rb:60:in `chdir'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer/pod_source_preparer.rb:60:in `block in run_prepare_command'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/user_interface.rb:64:in `section'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer/pod_source_preparer.rb:59:in `run_prepare_command'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer/pod_source_preparer.rb:37:in `prepare!'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer/pod_source_installer.rb:61:in `install!'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:365:in `install_source_of_pod'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:330:in `block (2 levels) in install_pod_sources'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/user_interface.rb:85:in `titled_section'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:329:in `block in install_pod_sources'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:321:in `each'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:321:in `install_pod_sources'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:164:in `block in download_dependencies'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/user_interface.rb:64:in `section'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:162:in `download_dependencies'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/installer.rb:117:in `install!'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/command/install.rb:41:in `run'
    /Library/Ruby/Gems/2.3.0/gems/claide-1.0.2/lib/claide/command.rb:334:in `run'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/lib/cocoapods/command.rb:52:in `run'
    /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.4.0/bin/pod:55:in `<top (required)>'
    /usr/local/bin/pod:22:in `load'
    /usr/local/bin/pod:22:in `<main>'
    

    Error output from CocoaPods: ↳ /bin/bash: line 3: /Users/satyajits/dev/flutter/bluetooth_example/Pods/!ProtoCompiler/protoc: No such file or directory

    [!] `<PBXGroup UUID=`97C146E51CF9000F007C117D`>` attempted to initialize an object with an unknown UUID. `CF3B75C9A7D2FA2A4C99F110` for attribute: `children`. This can be the result of a merge and  the unknown UUID is being discarded.
    

    Error running pod install Error launching application on iPhone X.

    ios-podspec 
    opened by ssarangi 18
  • Advertising and turning hardware on/off

    Advertising and turning hardware on/off

    Covers #47

    Unfortunately I brought a dependency for permissions that is giving me a bad time when compiling on iOS. Help is appreciated.

    Turning hw on/off should work on iOS but so far is untested. Advertising not implemented on iOS at all.

    opened by fmatosqg 18
  • Android X ScanResult empty list

    Android X ScanResult empty list

    Hello community,

    I'm using Android X and Android 9 devices for testing. For Android X I've a huge problem. The ScanResults are always empty. On Android 9 Devices it shows me the correct ScanResults.

    Same Project. compileSDKVersion is 29. I also tried to change the permissions from ACCESS_COARSE_LOCATION to ACCESS_FINE_LOCATION, but no changes.

    Does someone have any idea how to fix it?

    Thank you in advance cheers, Kevin

    opened by KevinRohn 17
  • setNotifyValue on multiple characteristics simultaneously

    setNotifyValue on multiple characteristics simultaneously

    I am unable to setNotifyValue for multiple characteristics on the same device. It always crashes when I try to setNotifyValue on the second characteristic. The code to register to notifications looks like this:

    void registerNotifications(Store<AppState> store, BleDevice device,
        BluetoothCharacteristic humidityCharacteristic,
        BluetoothCharacteristic temperatureCharacteristic,) async {
      await device.device.setNotifyValue(humidityCharacteristic, true);
      device.device.onValueChanged(humidityCharacteristic).listen((value) {
        device.setHumidity(LittleEndianExtractor.extractDouble(value));
        store.dispatch(new BleDeviceNewValue(device: device));
      });
    
      await device.device.setNotifyValue(temperatureCharacteristic, true);
      device.device.onValueChanged(temperatureCharacteristic).listen((value) {
        device.setTemperature(LittleEndianExtractor.extractDouble(value));
        store.dispatch(new BleDeviceNewValue(device: device));
      });
    }
    

    I get the following runtime error message

    D/BluetoothGatt(19458): setCharacteristicNotification() - uuid: 00001235-b38d-4985-720e-0f993a68ee41 enable: true
    E/flutter (19458): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
    E/flutter (19458): PlatformException(set_notification_error, error when writing the descriptor, null)
    E/flutter (19458): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:547:7)
    E/flutter (19458): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:279:18)
    E/flutter (19458): <asynchronous suspension>
    E/flutter (19458): #2      BluetoothDevice.setNotifyValue (file:///home/psachs/.pub-cache/hosted/pub.dartlang.org/flutter_blue-0.3.3/lib/src/bluetooth_device.dart:170:41)
    E/flutter (19458): <asynchronous suspension>
    E/flutter (19458): #3      registerNotifications.<anonymous closure> (package:ble_scanner/middlerware/ble_middleware.dart:166:19)
    E/flutter (19458): #4      _RootZone.run (dart:async/zone.dart:1376:54)
    E/flutter (19458): #5      _FutureListener.handleWhenComplete (dart:async/future_impl.dart:151:18)
    E/flutter (19458): #6      Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:607:39)
    E/flutter (19458): #7      Future._propagateToListeners (dart:async/future_impl.dart:663:37)
    E/flutter (19458): #8      Future._complete (dart:async/future_impl.dart:471:7)
    E/flutter (19458): #9      _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
    E/flutter (19458): #10     BluetoothDevice.setNotifyValue (file:///home/psachs/.pub-cache/hosted/pub.dartlang.org/flutter_blue-0.3.3/lib/src/bluetooth_device.dart)
    E/flutter (19458): <asynchronous suspension>
    E/flutter (19458): #11     registerNotifications (package:ble_scanner/middlerware/ble_middleware.dart:165:17)
    E/flutter (19458): <asynchronous suspension>
    E/flutter (19458): #12     handleDeviceConnection.<anonymous closure>.<anonymous closure> (package:ble_scanner/middlerware/ble_middleware.dart:138:15)
    E/flutter (19458): #13     _RootZone.runUnary (dart:async/zone.dart:1381:54)
    E/flutter (19458): #14     _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
    E/flutter (19458): #15     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:637:45)
    E/flutter (19458): #16     Future._propagateToListeners (dart:async/future_impl.dart:666:32)
    E/flutter (19458): #17     Future._complete (dart:async/future_impl.dart:471:7)
    E/flutter (19458): #18     _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
    E/flutter (19458): #19     BluetoothDevice.discoverServices (file:///home/psachs/.pub-cache/hosted/pub.dartlang.org/flutter_blue-0.3.3/lib/src/bluetooth_device.dart)
    E/flutter (19458): <asynchronous suspension>
    E/flutter (19458): #20     handleDeviceConnection.<anonymous closure> (package:ble_scanner/middlerware/ble_middleware.dart:120:25)
    E/flutter (19458): #21     _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
    E/flutter (19458): #22     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330:11)
    E/flutter (19458): #23     _DelayedData.perform (dart:async/stream_impl.dart:578:14)
    E/flutter (19458): #24     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:694:11)
    E/flutter (19458): #25     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:654:7)
    E/flutter (19458): #26     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
    E/flutter (19458): #27     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
    
    opened by psachs 17
  • AdvertisementData contains empty values on iOS

    AdvertisementData contains empty values on iOS

    Hi,

    On iOS, I'm not seeing any data for the following properties on AdvertisementData in my ScanResult event stream handler:

    • localName
    • manufacturerData
    • serviceData

    I observed this to be consistent over ScanResults for responses for 19 different devices.

    localName returns an empty String, and manufacturerData and serviceData return an empty List<int>.

    Let me know if I can provide more details or if I can help in troubleshooting, debugging, or verifying a fix.

    Thanks.

    opened by ryanhanks 16
  • Queue GATT operations, refactor reply channels

    Queue GATT operations, refactor reply channels

    Bluetooth GATT operations cannot run concurrently, so they must be queued up to let old operations finish before a new one is triggered.

    Also, there is no need for a separate EventChannel for every kind of operation; answers (except for scanning) are now sent via the plugin's main MethodChannel.

    this mostly does #11, and fixes #30

    opened by dturing 16
  • Connnect BLE devcie error,  under flutter v1.5.9 pre147

    Connnect BLE devcie error, under flutter v1.5.9 pre147

    I run the example under latest flutter (1.5.9 pre147) version, met an error.

    SCAN action is ok, the problem occurred while click CONNECT button.

    detail error message as below:

    D/BluetoothGatt( 4136): onClientConnectionState() - status=0 clientIf=5 device=10:CE:A9:2F:73:3F
    D/FlutterBluePlugin( 4136): [onConnectionStateChange] status: 0 newState: 2
    W/BluetoothGatt( 4136): Unhandled exception in callback
    W/BluetoothGatt( 4136): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Binder:4136_3
    W/BluetoothGatt( 4136): 	at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605)
    W/BluetoothGatt( 4136): 	at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:515)
    W/BluetoothGatt( 4136): 	at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:74)
    W/BluetoothGatt( 4136): 	at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:163)
    W/BluetoothGatt( 4136): 	at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:152)
    W/BluetoothGatt( 4136): 	at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:95)
    W/BluetoothGatt( 4136): 	at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:82)
    W/BluetoothGatt( 4136): 	at com.pauldemarco.flutterblue.FlutterBluePlugin$8.onConnectionStateChange(FlutterBluePlugin.java:757)
    W/BluetoothGatt( 4136): 	at android.bluetooth.BluetoothGatt$1$4.run(BluetoothGatt.java:262)
    W/BluetoothGatt( 4136): 	at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:770)
    W/BluetoothGatt( 4136): 	at android.bluetooth.BluetoothGatt.access$200(BluetoothGatt.java:39)
    W/BluetoothGatt( 4136): 	at android.bluetooth.BluetoothGatt$1.onClientConnectionState(BluetoothGatt.java:257)
    W/BluetoothGatt( 4136): 	at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:71)
    W/BluetoothGatt( 4136): 	at android.os.Binder.execTransact(Binder.java:735)
    D/BluetoothManager( 4136): getConnectionState()
    D/BluetoothManager( 4136): getConnectedDevices
    I/flutter ( 4136): State refreshed: BluetoothDeviceState.connected
    D/BluetoothGatt( 4136): onConnectionUpdated() - Device=10:CE:A9:2F:73:3F interval=6 latency=0 timeout=500 status=0
    D/BluetoothGatt( 4136): onConnectionUpdated() - Device=10:CE:A9:2F:73:3F interval=36 latency=0 timeout=500 status=0
    D/BluetoothGatt( 4136): close()
    D/BluetoothGatt( 4136): unregisterApp() - mClientIf=5
    

    flutter_blue: 0.5(git: 6f6fa30d77c7d935)

    Any one can give some advice, thank you!

    opened by guixue 15
  • Filter devices in flutter_blue

    Filter devices in flutter_blue

    I use flutter_blue to scan ble devices for social distancing app. However I'm not sure if what I did is correct. Since I make it general on scanning devices, I cannot know their characteristic and all I know is I only need to scan phone devices. Before I added the filtering which I use 'where' while scanning, it's functioning well even though it scan not just mobile devices but all devices. After I added them, it does not working at all even the floatingbutton to tap to scan devices.

    Here is my code before I add the filtering:

    FlutterBlue flutterBlue = FlutterBlue.instance;

    List scanResultList = []; bool _isScanning = false;

    @override initState() { super.initState(); // reset bluetooth initBle(); }

    void initBle() { // listener to get BLE scan status flutterBlue.isScanning.listen((isScanning) { _isScanning = isScanning; setState(() {}); }); }

    /* scan start or stop function */ scan() async { if (!_isScanning) { // if not scanning // Delete the previously scanned list scanResultList.clear(); // Start scanning, timeout 4 seconds flutterBlue.startScan(timeout: Duration(seconds: 4)); // scan result listener flutterBlue.scanResults.listen((results) { // List Copy the results value of the form to scanResultList scanResultList = results; // UI renewal setState(() {}); }); } else { // Stop scanning if scanning flutterBlue.stopScan(); } }

    And this is my code after I tried to filter them:

    FlutterBlue flutterBlue = FlutterBlue.instance;

    List scanResultList = []; bool _isScanning = false;

    @override initState() { super.initState(); // reset bluetooth initBle(); NotificationWidget.init(); }

    void initBle() { // listener to get BLE scan status flutterBlue.isScanning.listen((isScanning) { _isScanning = isScanning; setState(() {}); }); }

    /* scan start or stop function */ scan() async { if (!_isScanning) { // if not scanning // Delete the previously scanned list scanResultList.clear(); // Start scanning, timeout 4 seconds final scanResult = FlutterBlue.instance.scan().where((scanResult) { // Filter devices by manufacturer data and local name final advertisingData = scanResult.advertisementData; final deviceName = scanResult.device.name; return (advertisingData.manufacturerData[0x004C] == [0x02, 0x15] || advertisingData.manufacturerData[0x0051] != null) && deviceName.startsWith('Phone'); }); // scan result listener flutterBlue.scanResults.listen((results) { // List Copy the results value of the form to scanResultList scanResultList = results; // UI renewal setState(() {}); }); } else { // Stop scanning if scanning flutterBlue.stopScan(); } }

    opened by hhcng 0
  • doesn't display names of bluetooth list IOS IPHONE DEVICE

    doesn't display names of bluetooth list IOS IPHONE DEVICE

    doesn't display names of bluetooth list IOS IPHONE DEVICE, but on android device displaying Name with Address so user easily with connect and know about connect with which device... in IOS, we are getting only some ids of bluetooth list also number of devices list(unnecessary devices)

    pls check below SS... https://user-images.githubusercontent.com/70749329/209533013-4a69c1d2-eee3-46eb-b497-464e57bc0778.png

    @pauldemarco pls help me

    opened by insysinfo 0
  • How to diconnect the connected device when app is quit

    How to diconnect the connected device when app is quit

    if the app quit with some connected device, then next time enter into app, the device shows still connected, but cann't operate, even disconnect it. so i want to disconnect the connectd device when app is quit, is anyone knows how to make it. thanks

    opened by yudeying918 1
  • Can't to Scan and Connect in FlutterBlue library.

    Can't to Scan and Connect in FlutterBlue library.

    Hi....

    As am new to Flutter Bluetooth Technology. I am trying to communicate two android devices with the help of Flutter Blue.

    When am trying to scan the devices in my android mobile , it doesn't show the actual real devices like other mobile phones or laptops, but other than this it shows the smart brand devices. But that's also not connecting through the Flutter Blue app.

    I want to transfer the data between two android devices with the Flutter Bluetooth technology.

    Can anyone please assist me for sort out me from this issue.

    Thanks in advance.

    opened by Rajeswari-Kadarkaraiyandi 0
  • Does not work while in background

    Does not work while in background

    I am working on a part of an indoor localization project. I need my Flutter application scan and get Mac addresses and RSSI values of Wifi and Bluetooth devices. I am using flutter_blue for bluetooth scans and wifi_scan for Wifi scans. The application works well while in the foreground but scans are failing when the application is in background.

    What I have tried so far:

    Is there a way?

    opened by baranacikgoz 1
Releases(v0.7.2)
  • v0.7.2(Apr 20, 2020)

    Merged in performance fix for Guid initializers. Merged in allowDuplicates option for startScan. Updated rxdart dependency to the latest (0.24.0).

    Source code(tar.gz)
    Source code(zip)
  • v0.7.1+1(Apr 8, 2020)

    Merged in fix for constructor platform error when running on emulator. discoverServices now returns exception when called on a device that's not connected.

    Source code(tar.gz)
    Source code(zip)
  • v0.7.1(Apr 4, 2020)

    Fixed an issue that caused false notifications when writing characteristics. Stability improvements when building for iOS. Add toString to all Bluetooth classes. Other minor bug/documentation fixes.

    Source code(tar.gz)
    Source code(zip)
  • v0.7.0(Mar 31, 2020)

    Removed minSdk declaration for Android. Fixed Android permissions issue causing empty scan results. Fixed iOS permissions issue that caused build errors. Various minor fixes to documentation. Supports v2 android embedding.

    Source code(tar.gz)
    Source code(zip)
Owner
Paul DeMarco
Paul DeMarco
FlutterBleLib - A library for all your Bluetooth Low Energy needs in Flutter.

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

null 4 Jun 10, 2022
Bluetooth Low Energy library for Flutter with support for simulating peripherals

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

intent 509 Jan 3, 2023
A Flutter Template to communicate with an esp32 over bluetooth

Flutter Esp32 Bluetooth Template Changes in android/ [1 if you take the code to an other project, 2 still nessesarely]: Change minSdkVersion from 16 t

0x4d/Martin Loretz 23 Dec 20, 2022
null 5 Nov 21, 2022
This flutter app will help you to connect to Bluetooth Devices (like, HC-05)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Riyad Al-Ali 1 Jun 5, 2022
Flutter basic implementation for Classical Bluetooth (only RFCOMM for now)

flutter_bluetooth_serial Flutter basic implementation for Classical Bluetooth (only RFCOMM for now). Features The first goal of this project, started

null 1 Nov 7, 2022
I have created app to connect printer with bluetooth. And I already fix library bugs

flutter_bluetooth_printer A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to ge

Bounphone KOSADA 1 May 11, 2022
A project to get data from a fitbit device using bluetooth

Flutter 2 Boilerplate (version 1.3.0) A boilerplate project created in flutter. Boilerplate supports both web and mobile. VSCode is recommended in thi

Vajira Att 0 Dec 16, 2021
EI Blue - Edge Impulse Data Capture Over Bluetooth

EI Blue - Edge Impulse Data Capture Over Bluetooth Purpose of this project is to enable embedded engineers to collect data from bluetooth enabled micr

Mithun Das 4 Dec 21, 2022
Flutter beacons plugin for Android and iOS.

Beacons Flutter plugin to work with beacons. Supports Android API 16+ and iOS 8+. Features: Automatic permission management Ranging Monitoring (includ

Loup 76 Jan 6, 2023
Flutter NFC reader plugin for iOS and Android

Flutter NFC Reader & Writer A new flutter plugin to help developers looking to use internal hardware inside iOS or Android devices for reading and wri

Matteo Crippa 321 Dec 30, 2022
A Flutter plugin for turning your device into a beacon.

Beacon Broadcast plugin for Flutter A Flutter plugin for turning your device into a beacon. Usage To use this plugin, add beacon_broadcast as a depend

Paulina Szklarska 75 Dec 14, 2022
Flutter plugin for accessing the NFC features on Android and iOS.

nfc_manager Flutter plugin for accessing the NFC features on Android and iOS. Note: This plugin depends on NFCTagReaderSession (requires iOS 13.0 or l

null 126 Jan 1, 2023
Flutter library that handles BLE operations for multiple devices.

Flutter reactive BLE library Flutter library that handles BLE operations for multiple devices. Usage The reactive BLE lib supports the following: BLE

Philips Hue 473 Jan 4, 2023
Ready for Building Production-Ready Healthcare/ Doctor Consult Android and iOS app UI using Flutter.

Production-Ready Doctor Consultant App - Flutter UI Watch it on YouTube Packages we are using: flutter_svg: link Complete Source code (Patreon) In thi

Abu Anwar 211 Jan 1, 2023
ESC/POS (thermal, receipt) printing for Flutter & Dart (Android/iOS)

esc_pos_bluetooth The library allows to print receipts using a Bluetooth printer. For WiFi/Ethernet printers, use esc_pos_printer library. TODO (PRs a

Andrey 175 Jan 6, 2023
Bluetooth plugin for Flutter

Introduction FlutterBlue is a bluetooth plugin for Flutter, a new app SDK to help developers build modern multi-platform apps. Alpha version This libr

Paul DeMarco 2.2k Jan 5, 2023
Using Bluetooth plugin in Flutter (flutter_bluetooth_serial)

Flutter Bluetooth NOTE: This is the updated version of the app (using flutter_bluetooth_serial 0.2.2). This version has much fewer bugs and provides a

Souvik Biswas 179 Nov 22, 2022
FlutterBleLib - A library for all your Bluetooth Low Energy needs in Flutter.

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

null 4 Jun 10, 2022
Bluetooth Low Energy library for Flutter with support for simulating peripherals

FlutterBleLib A library for all your Bluetooth Low Energy needs in Flutter. Internally utilises Polidea's MultiPlatformBleAdapter, which runs on RxAnd

intent 509 Jan 3, 2023