From 8d8e3c8cd20b0fbacdc7503b6ce7aea91ba7dc94 Mon Sep 17 00:00:00 2001 From: Ali EP Date: Tue, 21 Sep 2021 17:12:22 +0430 Subject: [PATCH 1/3] fix timer throws out of the scope --- lib/src/bluetooth_device.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/bluetooth_device.dart b/lib/src/bluetooth_device.dart index ca3bb9ba..01961b0b 100644 --- a/lib/src/bluetooth_device.dart +++ b/lib/src/bluetooth_device.dart @@ -22,6 +22,7 @@ class BluetoothDevice { Duration? timeout, bool autoConnect = true, }) async { + final completer = Completer(); var request = protos.ConnectRequest.create() ..remoteId = id.toString() ..androidAutoConnect = autoConnect; @@ -30,7 +31,8 @@ class BluetoothDevice { if (timeout != null) { timer = Timer(timeout, () { disconnect(); - throw TimeoutException('Failed to connect in time.', timeout); + completer.completeError( + TimeoutException('Failed to connect in time.', timeout)); }); } @@ -41,7 +43,9 @@ class BluetoothDevice { timer?.cancel(); - return; + completer.complete(); + + return completer.future; } /// Cancels connection to the Bluetooth Device From 6bfe0958722cb9f746c930fdc0dae15875d9ec8b Mon Sep 17 00:00:00 2001 From: Ali EP Date: Tue, 21 Sep 2021 17:12:35 +0430 Subject: [PATCH 2/3] update deprecated attributes --- example/lib/main.dart | 4 ++-- example/lib/widgets.dart | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index e4a55a1a..0b47da07 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -7,7 +7,7 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:flutter_blue/flutter_blue.dart'; -import 'package:flutter_blue_example/widgets.dart'; +import 'widgets.dart'; void main() { runApp(FlutterBlueApp()); @@ -54,7 +54,7 @@ class BluetoothOffScreen extends StatelessWidget { 'Bluetooth Adapter is ${state != null ? state.toString().substring(15) : 'not available'}.', style: Theme.of(context) .primaryTextTheme - .subhead + .subtitle1 ?.copyWith(color: Colors.white), ), ], diff --git a/example/lib/widgets.dart b/example/lib/widgets.dart index aefdf262..23ae5949 100644 --- a/example/lib/widgets.dart +++ b/example/lib/widgets.dart @@ -135,7 +135,7 @@ class ServiceTile extends StatelessWidget { children: [ Text('Service'), Text('0x${service.uuid.toString().toUpperCase().substring(4, 8)}', - style: Theme.of(context).textTheme.body1?.copyWith( + style: Theme.of(context).textTheme.bodyText1?.copyWith( color: Theme.of(context).textTheme.caption?.color)) ], ), @@ -183,7 +183,7 @@ class CharacteristicTile extends StatelessWidget { Text('Characteristic'), Text( '0x${characteristic.uuid.toString().toUpperCase().substring(4, 8)}', - style: Theme.of(context).textTheme.body1?.copyWith( + style: Theme.of(context).textTheme.bodyText1?.copyWith( color: Theme.of(context).textTheme.caption?.color)) ], ), @@ -245,7 +245,7 @@ class DescriptorTile extends StatelessWidget { Text('0x${descriptor.uuid.toString().toUpperCase().substring(4, 8)}', style: Theme.of(context) .textTheme - .body1 + .bodyText1 ?.copyWith(color: Theme.of(context).textTheme.caption?.color)) ], ), @@ -289,11 +289,11 @@ class AdapterStateTile extends StatelessWidget { child: ListTile( title: Text( 'Bluetooth adapter is ${state.toString().substring(15)}', - style: Theme.of(context).primaryTextTheme.subhead, + style: Theme.of(context).primaryTextTheme.subtitle1, ), trailing: Icon( Icons.error, - color: Theme.of(context).primaryTextTheme.subhead?.color, + color: Theme.of(context).primaryTextTheme.subtitle1?.color, ), ), ); From 1486550dc280c8c49cb216d835f84e8de2495eed Mon Sep 17 00:00:00 2001 From: Ali EP Date: Tue, 21 Sep 2021 17:13:32 +0430 Subject: [PATCH 3/3] update version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 220c089d..f000666d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_blue description: Flutter plugin for connecting and communicating with Bluetooth Low Energy devices, on Android and iOS -version: 0.8.0 +version: 0.8.1 homepage: https://github.com/pauldemarco/flutter_blue environment: