flutter_bluetooth_serial_caravanas 0.2.13

  • Readme
  • Changelog
  • Example
  • Installing
  • 61

flutter_bluetooth_serial #

pub package

Flutter basic implementation for Classical Bluetooth (only RFCOMM for now).

Features #

The first goal of this project, started by caravanas was making an interface for Serial Port Protocol (HC-05 Adapter). Now the plugin features:

  • Adapter status monitoring,

  • Turning adapter on and off,

  • Opening settings,

  • Discovering devices (and requesting discoverability),

  • Listing bonded devices and pairing new ones,

  • Connecting to multiple devices at the same time,

  • Sending and recieving data (multiple connections).

The plugin (for now) uses Serial Port profile for moving data over RFCOMM, so make sure there is running Service Discovery Protocol that points to SP/RFCOMM channel of the device. There could be max up to 7 Bluetooth connections.

For now there is only Android support.

Getting Started #

Depending

# Add dependency to `pubspec.yaml` of your project.
dependencies:
  # ...
  flutter_bluetooth_serial: ^0.2.2

Installing

# With pub manager
pub get
# or with Flutter
flutter pub get

Importing

import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';

Usage

You should look to the Dart code of the library (mostly documented functions) or to the examples code.

// Some simplest connection :F
try {
    BluetoothConnection connection = await BluetoothConnection.toAddress(address);
    print('Connected to the device');

    connection.input.listen((Uint8List data) {
        print('Data incoming: ${ascii.decode(data)}');
        connection.output.add(data); // Sending data

        if (ascii.decode(data).contains('!')) {
            connection.finish(); // Closing connection
            print('Disconnecting by local host');
        }
    }).onDone(() {
        print('Disconnected by remote request');
    });
}
catch (exception) {
    print('Cannot connect, exception occured');
}

Note: Work is underway to make the communication easier than operations on byte streams. See #41 for discussion about the topic.

Examples

Check out example application with connections with both Arduino HC-05 and Raspberry Pi (RFCOMM) Bluetooth interfaces.

Main screen and optionsDiscovery and connectingSimple chat with serverBackground connection

To-do list #

  • Add some utils to easier manage BluetoothConnection (see discussion #41),
  • Allow connection method/protocol/UUID specification,
  • Listening/server mode,
  • Recognizing and displaying BluetoothClass of device,
  • Maybe integration with flutter_blue one day ;)

You might also want to check milestones.

Descartamos la geolocalizacion

[0.2.13] - 2019-11-28 #

  • Restaurando...

[0.2.2] - 2019-08-19 #

Patch release.

  • Fix closing connections which are not listening to input (solved #60),
  • Add more clear example of detecting which side caused disconnection,
  • Add exception on adding to output if connection closed,
  • BluetoothConnection cancel is deprecated now, use close instead. It was stupid to name cancel something that closes (it was even documented that way, lol).

[0.2.1] - 2019-08-05 #

Patch release.

  • apply patch #48 for some disconnection issues,
  • update ChatPage to newer API,
  • fix and update AndroidX declaration.

[0.2.0] - 2019-07-02 #

Two big features packs:

  • Bonding (Pairing):
    • starting outgoing pairing requests,
    • handling incoming pairing requests,
    • remove current bondings to devices,
  • Discoverability!
    • requesting discoverable mode for specified duration,
    • example with timeout countdown,
    • checking discoverable mode.

And few more features:

  • get/set for local (discoverable) device name,
  • getting local adapter address (with some hacks to work on newer Androids),
  • checking for isConnected for discovered or bonded devices,
  • fixed few broadcast receiver leaks.

[0.1.1] - 2019-07-01 #

  • Patch #43 for "Error when meet unknown devices".

[0.1.0] - 2019-06-19 #

Pull request #35 by @PsychoXIVI changes a lot:

  • Discovering other devices,
  • Multiple connections,
  • Interesting example application,
  • Enabling/Disabling Bluetooth,
  • Byte streams,
  • Overall improvements and fixes.

[0.0.5] - 2019-03-18 #

  • Upgrade for AndroidX support (thanks @akilinomendez)
  • New default constructor (thanks @MohiuddinM)
  • Added method write passing byte[] (thanks @rafaelterada)
  • Upgrade to Android Studio 3.3.2

[0.0.4] - 2018-12-20 #

  • Unsupported value error correction (thanks @rafaelterada)
  • Added openSettings, which opens the bluetooth settings screen (thanks @rafaelterada)

[0.0.3] - 2018-11-22 #

  • async connection and null exception handled (thanks @MohiuddinM)

[0.0.2] - 2018-09-27 #

  • isConnected Implementation (thanks @Riscue)

[0.0.1] - 2018-08-20 #

  • Only Android support.

example/lib/main.dart

import 'package:flutter/material.dart';

import './MainPage.dart';

void main() => runApp(new ExampleApplication());

class ExampleApplication extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MainPage()
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_bluetooth_serial_caravanas: ^0.2.13

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_bluetooth_serial_caravanas/BluetoothBondState.dart';
import 'package:flutter_bluetooth_serial_caravanas/BluetoothConnection.dart';
import 'package:flutter_bluetooth_serial_caravanas/BluetoothDevice.dart';
import 'package:flutter_bluetooth_serial_caravanas/BluetoothDeviceType.dart';
import 'package:flutter_bluetooth_serial_caravanas/BluetoothDiscoveryResult.dart';
import 'package:flutter_bluetooth_serial_caravanas/BluetoothPairingRequest.dart';
import 'package:flutter_bluetooth_serial_caravanas/BluetoothState.dart';
import 'package:flutter_bluetooth_serial_caravanas/FlutterBluetoothSerial.dart';
import 'package:flutter_bluetooth_serial_caravanas/flutter_bluetooth_serial.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
39
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Jul 12, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:flutter_bluetooth_serial_caravanas/BluetoothBondState.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_bluetooth_serial_caravanas/BluetoothBondState.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_bluetooth_serial_caravanas/BluetoothBondState.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_bluetooth_serial_caravanas/BluetoothBondState.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_bluetooth_serial_caravanas that is a package requiring null.

Health suggestions

Fix lib/BluetoothConnection.dart. (-0.50 points)

Analysis of lib/BluetoothConnection.dart reported 1 hint:

line 20 col 13: The value of the field '_id' isn't used.

Format lib/BluetoothBondState.dart.

Run flutter format to format lib/BluetoothBondState.dart.

Format lib/BluetoothDevice.dart.

Run flutter format to format lib/BluetoothDevice.dart.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/BluetoothDeviceType.dart (Run flutter format to format lib/BluetoothDeviceType.dart.)
  • lib/BluetoothPairingRequest.dart (Run flutter format to format lib/BluetoothPairingRequest.dart.)
  • lib/BluetoothState.dart (Run flutter format to format lib/BluetoothState.dart.)
  • lib/flutter_bluetooth_serial.dart (Run flutter format to format lib/flutter_bluetooth_serial.dart.)

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://github.com/caravanas/flutter_bluetooth_serial was unreachable.

Issue tracker URL doesn't exist. (-10 points)

At the time of the analysis the issue_tracker field https://github.com/caravanas/flutter_bluetooth_serial/issues was unreachable.

Repository URL doesn't exist. (-10 points)

At the time of the analysis the repository field https://github.com/caravanas/flutter_bluetooth_serial was unreachable.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-a <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety