Skip to content

Commit

Permalink
fixed Dart Analysis warnings
Browse files Browse the repository at this point in the history
1.1.1 -> 1.1.2
  • Loading branch information
boskokg committed Feb 24, 2022
1 parent 8e4b37b commit 2b0798b
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 70 deletions.
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.2
* Remove connect to BLE device after BLE device has disconnected #11 (fixed by sophisticode)
* fixed Dart Analysis warnings

## 1.1.1
* Copyright reverted to Paul DeMarco

Expand All @@ -11,3 +15,42 @@
## 1.0.0

* First public release

## Versions made while fixing bugs in fork https://github.com/boskokg/flutter_blue:

## 0.12.0

Supporting Android 12 Bluetooth permissions. #940

## 0.12.0

Delay Bluetooth permission & turn-on-Bluetooth system popups on iOS #964

## 0.11.0

The timeout was throwing out of the Future's scope #941
Expose onValueChangedStream #882
Android: removed V1Embedding
Android: removed graddle.properties
Android: enable background usage
Android: cannot handle devices that do not set CCCD_ID (2902) includes BLUNO #185 #797
Android: add method for getting bonded devices #586
Ios: remove support only for x86_64 simulators
Ios: Don't initialize CBCentralManager until needed #599

## 0.10.0

mtuRequest returns the negotiated MTU
Android: functions to turn on/off bluetooth
Android: add null check if channel is already teared down
Android: code small refactoring (fixed AS warnings)
Android: add null check if channel is already teared down
Ios: widen protobuf version allowed

## 0.9.0

Android migrate to mavenCentral.
Android support build on Macs M1
Android protobuf-gradle-plugin:0.8.15 -> 0.8.17
Ios example upgrade to latest flutter 2.5
deprecated/removed widgets fixed in example
48 changes: 26 additions & 22 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'widgets.dart';

void main() {
runApp(FlutterBlueApp());
runApp(const FlutterBlueApp());
}

class FlutterBlueApp extends StatelessWidget {
const FlutterBlueApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -26,7 +28,7 @@ class FlutterBlueApp extends StatelessWidget {
builder: (c, snapshot) {
final state = snapshot.data;
if (state == BluetoothState.on) {
return FindDevicesScreen();
return const FindDevicesScreen();
}
return BluetoothOffScreen(state: state);
}),
Expand All @@ -47,7 +49,7 @@ class BluetoothOffScreen extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(
const Icon(
Icons.bluetooth_disabled,
size: 200.0,
color: Colors.white54,
Expand All @@ -60,7 +62,7 @@ class BluetoothOffScreen extends StatelessWidget {
?.copyWith(color: Colors.white),
),
ElevatedButton(
child: Text('TURN ON'),
child: const Text('TURN ON'),
onPressed: Platform.isAndroid
? () => FlutterBluePlus.instance.turnOn()
: null,
Expand All @@ -73,14 +75,16 @@ class BluetoothOffScreen extends StatelessWidget {
}

class FindDevicesScreen extends StatelessWidget {
const FindDevicesScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Find Devices'),
title: const Text('Find Devices'),
actions: [
ElevatedButton(
child: Text('TURN OFF'),
child: const Text('TURN OFF'),
style: ElevatedButton.styleFrom(
primary: Colors.black,
onPrimary: Colors.white,
Expand All @@ -92,15 +96,15 @@ class FindDevicesScreen extends StatelessWidget {
],
),
body: RefreshIndicator(
onRefresh: () =>
FlutterBluePlus.instance.startScan(timeout: Duration(seconds: 4)),
onRefresh: () => FlutterBluePlus.instance
.startScan(timeout: const Duration(seconds: 4)),
child: SingleChildScrollView(
child: Column(
children: <Widget>[
StreamBuilder<List<BluetoothDevice>>(
stream: Stream.periodic(Duration(seconds: 2))
stream: Stream.periodic(const Duration(seconds: 2))
.asyncMap((_) => FlutterBluePlus.instance.connectedDevices),
initialData: [],
initialData: const [],
builder: (c, snapshot) => Column(
children: snapshot.data!
.map((d) => ListTile(
Expand All @@ -113,7 +117,7 @@ class FindDevicesScreen extends StatelessWidget {
if (snapshot.data ==
BluetoothDeviceState.connected) {
return ElevatedButton(
child: Text('OPEN'),
child: const Text('OPEN'),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
Expand All @@ -129,7 +133,7 @@ class FindDevicesScreen extends StatelessWidget {
),
StreamBuilder<List<ScanResult>>(
stream: FlutterBluePlus.instance.scanResults,
initialData: [],
initialData: const [],
builder: (c, snapshot) => Column(
children: snapshot.data!
.map(
Expand All @@ -155,15 +159,15 @@ class FindDevicesScreen extends StatelessWidget {
builder: (c, snapshot) {
if (snapshot.data!) {
return FloatingActionButton(
child: Icon(Icons.stop),
child: const Icon(Icons.stop),
onPressed: () => FlutterBluePlus.instance.stopScan(),
backgroundColor: Colors.red,
);
} else {
return FloatingActionButton(
child: Icon(Icons.search),
child: const Icon(Icons.search),
onPressed: () => FlutterBluePlus.instance
.startScan(timeout: Duration(seconds: 4)));
.startScan(timeout: const Duration(seconds: 4)));
}
},
),
Expand Down Expand Up @@ -268,8 +272,8 @@ class DeviceScreen extends StatelessWidget {
initialData: BluetoothDeviceState.connecting,
builder: (c, snapshot) => ListTile(
leading: (snapshot.data == BluetoothDeviceState.connected)
? Icon(Icons.bluetooth_connected)
: Icon(Icons.bluetooth_disabled),
? const Icon(Icons.bluetooth_connected)
: const Icon(Icons.bluetooth_disabled),
title: Text(
'Device is ${snapshot.data.toString().split('.')[1]}.'),
subtitle: Text('${device.id}'),
Expand All @@ -280,10 +284,10 @@ class DeviceScreen extends StatelessWidget {
index: snapshot.data! ? 1 : 0,
children: <Widget>[
IconButton(
icon: Icon(Icons.refresh),
icon: const Icon(Icons.refresh),
onPressed: () => device.discoverServices(),
),
IconButton(
const IconButton(
icon: SizedBox(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.grey),
Expand All @@ -302,17 +306,17 @@ class DeviceScreen extends StatelessWidget {
stream: device.mtu,
initialData: 0,
builder: (c, snapshot) => ListTile(
title: Text('MTU Size'),
title: const Text('MTU Size'),
subtitle: Text('${snapshot.data} bytes'),
trailing: IconButton(
icon: Icon(Icons.edit),
icon: const Icon(Icons.edit),
onPressed: () => device.requestMtu(223),
),
),
),
StreamBuilder<List<BluetoothService>>(
stream: device.services,
initialData: [],
initialData: const [],
builder: (c, snapshot) {
return Column(
children: _buildServiceTiles(snapshot.data!),
Expand Down
20 changes: 10 additions & 10 deletions example/lib/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ScanResultTile extends StatelessWidget {
final VoidCallback? onTap;

Widget _buildTitle(BuildContext context) {
if (result.device.name.length > 0) {
if (result.device.name.isNotEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -35,12 +35,12 @@ class ScanResultTile extends StatelessWidget {

Widget _buildAdvRow(BuildContext context, String title, String value) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 4.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(title, style: Theme.of(context).textTheme.caption),
SizedBox(
const SizedBox(
width: 12.0,
),
Expanded(
Expand Down Expand Up @@ -92,7 +92,7 @@ class ScanResultTile extends StatelessWidget {
title: _buildTitle(context),
leading: Text(result.rssi.toString()),
trailing: ElevatedButton(
child: Text('CONNECT'),
child: const Text('CONNECT'),
style: ElevatedButton.styleFrom(
primary: Colors.black,
onPrimary: Colors.white,
Expand Down Expand Up @@ -129,13 +129,13 @@ class ServiceTile extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (characteristicTiles.length > 0) {
if (characteristicTiles.isNotEmpty) {
return ExpansionTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Service'),
const Text('Service'),
Text('0x${service.uuid.toString().toUpperCase().substring(4, 8)}',
style: Theme.of(context).textTheme.bodyText1?.copyWith(
color: Theme.of(context).textTheme.caption?.color))
Expand All @@ -145,7 +145,7 @@ class ServiceTile extends StatelessWidget {
);
} else {
return ListTile(
title: Text('Service'),
title: const Text('Service'),
subtitle:
Text('0x${service.uuid.toString().toUpperCase().substring(4, 8)}'),
);
Expand Down Expand Up @@ -182,15 +182,15 @@ class CharacteristicTile extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Characteristic'),
const Text('Characteristic'),
Text(
'0x${characteristic.uuid.toString().toUpperCase().substring(4, 8)}',
style: Theme.of(context).textTheme.bodyText1?.copyWith(
color: Theme.of(context).textTheme.caption?.color))
],
),
subtitle: Text(value.toString()),
contentPadding: EdgeInsets.all(0.0),
contentPadding: const EdgeInsets.all(0.0),
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -243,7 +243,7 @@ class DescriptorTile extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text('Descriptor'),
const Text('Descriptor'),
Text('0x${descriptor.uuid.toString().toUpperCase().substring(4, 8)}',
style: Theme.of(context)
.textTheme
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_blue_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'dart:async';

import 'package:collection/collection.dart';
import 'package:convert/convert.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:rxdart/rxdart.dart';

import 'gen/flutterblueplus.pb.dart' as protos;
Expand Down
11 changes: 5 additions & 6 deletions lib/src/bluetooth_characteristic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BluetoothCharacteristic {
}
}

BehaviorSubject<List<int>> _value;
final BehaviorSubject<List<int>> _value;
Stream<List<int>> get value => Rx.merge([
_value.stream,
onValueChangedStream,
Expand All @@ -33,7 +33,7 @@ class BluetoothCharacteristic {
: uuid = Guid(p.uuid),
deviceId = DeviceIdentifier(p.remoteId),
serviceUuid = Guid(p.serviceUuid),
secondaryServiceUuid = (p.secondaryServiceUuid.length > 0)
secondaryServiceUuid = (p.secondaryServiceUuid.isNotEmpty)
? Guid(p.secondaryServiceUuid)
: null,
descriptors =
Expand Down Expand Up @@ -83,8 +83,7 @@ class BluetoothCharacteristic {
return FlutterBluePlus.instance._methodStream
.where((m) => m.method == "ReadCharacteristicResponse")
.map((m) => m.arguments)
.map((buffer) =>
new protos.ReadCharacteristicResponse.fromBuffer(buffer))
.map((buffer) => protos.ReadCharacteristicResponse.fromBuffer(buffer))
.where((p) =>
(p.remoteId == request.remoteId) &&
(p.characteristic.uuid == request.characteristicUuid) &&
Expand Down Expand Up @@ -133,7 +132,7 @@ class BluetoothCharacteristic {
.first
.then((w) => w.success)
.then((success) => (!success)
? throw new Exception('Failed to write the characteristic')
? throw Exception('Failed to write the characteristic')
: null)
.then((_) => null);
}
Expand Down Expand Up @@ -186,7 +185,7 @@ class CharacteristicProperties {
final bool notifyEncryptionRequired;
final bool indicateEncryptionRequired;

CharacteristicProperties(
const CharacteristicProperties(
{this.broadcast = false,
this.read = false,
this.writeWithoutResponse = false,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/bluetooth_descriptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
part of flutter_blue_plus;

class BluetoothDescriptor {
static final Guid cccd = new Guid("00002902-0000-1000-8000-00805f9b34fb");
static final Guid cccd = Guid("00002902-0000-1000-8000-00805f9b34fb");

final Guid uuid;
final DeviceIdentifier deviceId;
final Guid serviceUuid;
final Guid characteristicUuid;

BehaviorSubject<List<int>> _value;
final BehaviorSubject<List<int>> _value;
Stream<List<int>> get value => _value.stream;

List<int> get lastValue => _value.value;
Expand Down Expand Up @@ -76,7 +76,7 @@ class BluetoothDescriptor {
.first
.then((w) => w.success)
.then((success) => (!success)
? throw new Exception('Failed to write the descriptor')
? throw Exception('Failed to write the descriptor')
: null)
.then((_) => _value.add(value))
.then((_) => null);
Expand Down
Loading

2 comments on commit 2b0798b

@fabiototh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrCsabaToth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, can add this: TOTHLIFECARE/flutter_blue@2afeb5f

Formulate a PR against this (flutter_blue_plus instead of flutter_blue) repo so the maintainer can merge it

Please sign in to comment.