Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix timeout bug #941

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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),
),
],
Expand Down
10 changes: 5 additions & 5 deletions example/lib/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ServiceTile extends StatelessWidget {
children: <Widget>[
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))
],
),
Expand Down Expand Up @@ -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))
],
),
Expand Down Expand Up @@ -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))
],
),
Expand Down Expand Up @@ -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,
),
),
);
Expand Down
8 changes: 6 additions & 2 deletions lib/src/bluetooth_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BluetoothDevice {
Duration? timeout,
bool autoConnect = true,
}) async {
final completer = Completer<void>();
var request = protos.ConnectRequest.create()
..remoteId = id.toString()
..androidAutoConnect = autoConnect;
Expand All @@ -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));
});
}

Expand All @@ -41,7 +43,9 @@ class BluetoothDevice {

timer?.cancel();

return;
completer.complete();

return completer.future;
}

/// Cancels connection to the Bluetooth Device
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down