Thank you for your interest in the FlutterBle Library. Unfortunately this repository is not maintained anymore as we are focusing on developing native iOS (RxBluetootkKit) and Android (RxAndroidBle) libraries. Stay tuned!
FlutterBle Library is a Flutter library that supports BLE connections. It internally utilizes RxAndroidBle and RxBluetoothKit as native libs, which especially on Android helps a lot with many of known platform issues.
To start using Flutter, you have to prepare the environment. Here you can find the tutorial showing how to do this step by step.
- Setting log level
- Listening bluetooth adapter state
- Scanning devices
- Establish connection
- Listening to connection state changes
- Discovering services
- Reading characteristics
- Writing characteristics
- Listening to characteristic change notifications
Configuration & Installation
Add the snippet below to your
dependencies: flutter_ble_lib: "^1.0.0"
Package can be installed from the command line:
- with pub:
$ pub get
- with Flutter:
$ flutter packages get
Alternatively, your editor may support
pub get or
packages get. Refer to the documentation of your IDE to learn more.
iOS additional configuration
In order to make it work on iOS you need to make 2 additional steps:
use_frameworks!at the beginning of
config.build_settings['SWIFT_VERSION'] = '4.1.0'in
ios/Podfile file should have following changes:
+ use_frameworks! ... post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ENABLE_BITCODE'] = 'NO' + config.build_settings['SWIFT_VERSION'] = '4.1.0' end end end
Once the package is installed you can use:
First, you need to create a client. It is very important to maintain only one instance of the client in your application. You can do this via the method
Set up log level
After creating the client, you can set up a log level. There are a few defined log levels:
- NONE (default value)
You can set the log level via
and. You can also check the current level log via:
Bluetooth state checking
The library allows checking a Bluetooth state. You can register a listener that informs about state changes. It is possible via:
This method returns a stream that emits all Bluetooth state changes. If you want to get current Bluetooth state you can just call the method below
Methods presented above may return/emit the following values:
- UNKNOWN (default state)
The connection with the device
After creating the client, you can establish a connection with the device. There is a feature to scan for devices via:
FlutterBleLib.instance.startDeviceScan(scanMode, calbackType, uuidsArray)
method. This method returns a stream that emits scanned devices. The information about a device contains a
device id that may be used to create the connection. All you need to do is to call:
method. As a response you will get an information about the connected device. You can verify if the device is connected via
at any time. It is recommended to set up a monitor that allows getting an information about the connection being broken. The library provides this functionality via the following method
If any of the device connection breaks the stream emits information about it.
Once you are connected to your device, you can discover services, write, read or listen to notifications from characteristics.
Full library functionality is shown in example app.
Copyright 2018 Polidea Sp. z o.o Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.