flutter_ble_lib 1.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 37

FlutterBle Library

FlutterBle Library is a flutter library that supports ble connections. It uses RxAndroidBle and RxBluetoothKit as native libs.

Getting Started

To using Flutter you need to prepare the environment. Here you can find the tutorial showing how to do this, step by step.

Features

  • [x] Setting log level
  • [x] Listening bluetooth state
  • [x] Scanning devices
  • [x] Establish connection
  • [x] Listening connection state changes
  • [x] Reading services
  • [x] Reading characteristics
  • [x] Writing characteristics
  • [x] Listening characteristic notifications

Usage

Create Client

Firstly you need create client. It is very important to create only one single instance. You can do this via method

FlutterBleLib.instance.createClient(restoreId);

Set up log level

After creating the client, you can set up log level. There are a few defined log levels:

  • NONE (default value)
  • VERBOSE
  • DEBUG
  • INFO
  • WARNING
  • ERROR

You can set log level via

FlutterBleLib.instance.setLogLevel(logLevel);

and, you will get set log level as the response. You can also check current level log via:

FlutterBleLib.instance.logLevel();

Bluetooth state checking

Library allows to check bluetooth state. You can register listener that informs about state changes. It is possible via:

FlutterBleLib.instance.onStateChange()
 

This method returns stream that emits all bluetooth state changes. It is not the only one way to get information about bluetooth state. If you want to get current bluetooth state you can just call method

FlutterBleLib.instance.state()
 

to get current state.

There is a few defined current state:

  • UNKNOWN (default state)
  • RESETTING
  • UNSUPPORTED
  • UNAUTHORIZED
  • POWERED_OFF
  • POWERED_ON

The connection with the device

After creating client, you can establish connection with device. There is possibility to scan all devices via:

FlutterBleLib.instance.startDeviceScan(scanMode, calbackType, uuidsArray)
 

method. This method returns stream that emits scanned devices. The information about the device contains device id that is used to create connection. All you need to do is calling:

FlutterBleLib.instance.connectToDevice(deviceId, isAutoConnect)
 

method, as a response you will get information about connected device. You can check any time that device is connected via

FlutterBleLib.instance.isDeviceConnected(deviceId)

at any time. It’s good to set up the monitor that allows to get the information about breaking connection. Library provides this functionality via the following method

FlutterBleLib.instance.onDeviceConnectionChanged()
 

If some of the device's brake, this stream will emit information about this device.<br />

When you are connected with your device you can discover services, write, read or listen notification from characteristic via relevant method.

Full library functionality is shown in example app.

Maintainers

Konrad Krakowiak (konrad.krakowiak@polidea.com)<br/> Michał Mizera (michal.mizera@polidea.com)<br/> Michał Zieliński (michal.zielinski@polidea.com)<br/> Paweł Janeczek (pawel.janeczek@polidea.com)

License

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.

Maintained by

Polidea

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_ble_lib_example/ui/ble_devieces_screen.dart';
import 'package:flutter_ble_lib_example/ui/screen_on_boarding.dart';
import 'package:flutter_ble_lib_example/ui/screen_names.dart' as ScreenNames;

const Color polideaColor =  const Color.fromRGBO(25, 159, 217, 1.0);
void main() {
  runApp(new MaterialApp(
    home: new OnBoardingPager(),
    theme: new ThemeData(
      canvasColor: polideaColor,
      iconTheme: new IconThemeData(color: Colors.white),
      accentColor: Colors.pinkAccent,
      brightness: Brightness.dark,
    ),
    routes: <String, WidgetBuilder>{
      ScreenNames.bleDevicesScreen: (
          BuildContext context) => new BleDevicesScreen(),
    },
  ));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_ble_lib: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_ble_lib/flutter_ble_lib.dart';
  
Version Uploaded Documentation Archive
1.0.0 Mar 2, 2018 Go to the documentation of flutter_ble_lib 1.0.0 Download flutter_ble_lib 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
74
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
37
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <2.0.0