simple_flutter_ble

Last updated:

0 purchases

simple_flutter_ble Image
simple_flutter_ble Images
Add to Cart

Description:

simple flutter ble

simple_flutter_ble #
Flutter plugin for Bluetooth Low Energy
Features #

Can also discover devices based on the given list of service uuids
Listen to bluetooth connection changes
Can send data and wait for the response.
Listen to device connection changes
Subscribe to notification

Getting Started #
import 'package:flutter_ble/flutter_ble.dart';
copied to clipboard
Instantiate #
FlutterBle ble = FlutterBle();
copied to clipboard
or filter devices with service uuids
FlutterBle ble = FlutterBle(['ec75916b-2217-401d-a433-80411522b493']);
copied to clipboard
Start discovery #
ble.start();
//subscription method
//Listen to discovered devices
//this will trigger whether devices are added or removed
ble.discoveredDevices.listen((devices){

});
//Listen to bluetooth connection status
ble.startBluetoothListener();
ble.onBluetooth.listen((status){

});
copied to clipboard
Write, read and notify #
//Write
device.write('uuid', 'dynamic data');
//Wait for response
var data = device.writeWithResponse('uuid', 'dynamic data');
//read
var data = device.read('uuid');
//listen to notification
device.notify('uuid').listen((data){

});
copied to clipboard
Using implements #
class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> implements DeviceListener{
FlutterBle flutterBle = FlutterBle();
@override
void initState() {
super.initState();
flutterBle.start();
flutterBle.startBluetoothListener();
flutterBle.setListener(this);
}

@override
void onBluetoothConnected(bool status) {
// TODO: implement onBluetoothConnected
}

@override
void onBluetoothDisconnected(bool status) {
// TODO: implement onBluetoothDisconnected
}

@override
void onDeviceConnected(String address, bool status) {
// TODO: implement onDeviceConnected
}

@override
void onDeviceDisconnected(String address, bool status) {
// TODO: implement onDeviceDisconnected
}

@override
void onDiscoveredDevices(List<BLEDevice> devices) {
// TODO: implement onDiscoveredDevices
}

@override
void onNotify(data) {
// TODO: implement onNotify
}
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.