flutter_ble_peripheral 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 82

pub package Join the chat Dev: Workflow Master: Workflow

FlutterBlePeripheral #

This Flutter plugin allows a device to be used in Peripheral mode, and advertise data over BLE to central devices.

Help develop this plugin! #

If you want to contribute to this plugin, feel free to make issues and pull-requests.

Not stable #

Since this plugin is currently being developed, limited functionality will be available. Check the release page for the most recent release.

FunctionalityAndroidiOSDescription
Advertise UUIDSet and advertise a custom uuid.
Advertise custom serviceAdvertise a custom service.
Advertise custom characteristicAdvertise a custom characteristic with any of the following specifications.
Read characteristicEnable the possibility to read a value.
Write characteristicEnable the possibility to write a value.
Notify characteristicEnable the possibility to subscribe and notify a value.

0.1.0 #

Fixed several parts for Android:

  • Advertising local name
  • Advertising Manufacturer Data
  • Advertising Service Data

0.0.4 #

Fixed iOS advertising not working

0.0.3 #

Fixed callback on Android

0.0.2 #

Fixed flutter v2 embedding

0.0.1 #

Initial version of the library. This version includes:

  • broadcasting a custom UUID

example/lib/main.dart

/*
 * Copyright (c) 2020. Julian Steenbakker.
 * All rights reserved. Use of this source code is governed by a
 * BSD-style license that can be found in the LICENSE file.
 */

import 'package:flutter/material.dart';
import 'package:flutter_ble_peripheral/data.dart';
import 'package:flutter_ble_peripheral/main.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  FlutterBlePeripheral blePeripheral = FlutterBlePeripheral();
  AdvertiseData _data = AdvertiseData();
  bool _isBroadcasting = false;

  @override
  void initState() {
    super.initState();
    setState(() {
      _data.includeDeviceName = false;
      _data.uuid = 'bf27730d-860a-4e09-889c-2d8b6a9e0fe7';
      _data.manufacturerId = 1234;
      _data.manufacturerData = [
        1, 2, 3, 4, 5, 6];
    });
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    bool isAdvertising = await blePeripheral.isAdvertising();
    setState(() {
      _isBroadcasting = isAdvertising;
    });
  }

  void _toggleAdvertise() async {
    if (await blePeripheral.isAdvertising()) {
      blePeripheral.stop();
      setState(() {
        _isBroadcasting = false;
      });
    } else {
      blePeripheral.start(_data);
      setState(() {
        _isBroadcasting = true;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter BLE Peripheral'),
        ),
        body: Center(
            child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
              Text('Is advertising: ' + _isBroadcasting.toString()),
              Text('Current uuid is ' + _data.uuid),
              FlatButton(
                  onPressed: () => _toggleAdvertise(),
                  child: Text(
                    'Toggle advertising',
                    style: Theme.of(context)
                        .primaryTextTheme
                        .button
                        .copyWith(color: Colors.blue),
                  )),
            ])),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_ble_peripheral: ^0.1.0

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_ble_peripheral/data.dart';
import 'package:flutter_ble_peripheral/main.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
63
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
82
Learn more about scoring.

We analyzed this package on Jul 10, 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_ble_peripheral/data.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:flutter_ble_peripheral/data.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:flutter_ble_peripheral/data.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:flutter_ble_peripheral/data.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • flutter_ble_peripheral that is a package requiring null.

Health suggestions

Format lib/data.dart.

Run flutter format to format lib/data.dart.

Format lib/main.dart.

Run flutter format to format lib/main.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <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
Dev dependencies
flutter_test