Skip to content

Commit 1300f23

Browse files
committed
dartfmt on src folder.
1 parent 5b34e20 commit 1300f23

7 files changed

+113
-96
lines changed

lib/flutter_blue.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ library flutter_blue;
66

77
import 'dart:async';
88

9-
import 'package:flutter/services.dart';
10-
import 'gen/flutterblue.pb.dart' as protos;
11-
import 'package:meta/meta.dart';
129
import 'package:collection/collection.dart';
1310
import 'package:convert/convert.dart';
11+
import 'package:flutter/services.dart';
12+
import 'package:meta/meta.dart';
13+
14+
import 'gen/flutterblue.pb.dart' as protos;
1415

15-
part 'src/flutter_blue.dart';
16-
part 'src/constants.dart';
17-
part 'src/bluetooth_device.dart';
18-
part 'src/bluetooth_service.dart';
1916
part 'src/bluetooth_characteristic.dart';
2017
part 'src/bluetooth_descriptor.dart';
21-
part 'src/guid.dart';
18+
part 'src/bluetooth_device.dart';
19+
part 'src/bluetooth_service.dart';
20+
part 'src/constants.dart';
21+
part 'src/flutter_blue.dart';
22+
part 'src/guid.dart';

lib/src/bluetooth_characteristic.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ class BluetoothCharacteristic {
1313
final List<BluetoothDescriptor> descriptors;
1414
bool get isNotifying {
1515
try {
16-
var cccd = descriptors.singleWhere((d) =>
17-
d.uuid == BluetoothDescriptor.CCCD);
16+
var cccd =
17+
descriptors.singleWhere((d) => d.uuid == BluetoothDescriptor.CCCD);
1818
return ((cccd.value[0] & 0x01) > 0 || (cccd.value[0] & 0x02) > 0);
19-
} catch(e) {
19+
} catch (e) {
2020
return false;
2121
}
2222
}
23+
2324
List<int> value;
2425

2526
BluetoothCharacteristic(
@@ -32,17 +33,19 @@ class BluetoothCharacteristic {
3233
BluetoothCharacteristic.fromProto(protos.BluetoothCharacteristic p)
3334
: uuid = new Guid(p.uuid),
3435
serviceUuid = new Guid(p.serviceUuid),
35-
secondaryServiceUuid = (p.secondaryServiceUuid.length > 0) ? new Guid(p.secondaryServiceUuid): null,
36+
secondaryServiceUuid = (p.secondaryServiceUuid.length > 0)
37+
? new Guid(p.secondaryServiceUuid)
38+
: null,
3639
descriptors = p.descriptors
3740
.map((d) => new BluetoothDescriptor.fromProto(d))
3841
.toList(),
3942
properties = new CharacteristicProperties.fromProto(p.properties),
4043
value = p.value;
4144

4245
void updateDescriptors(List<BluetoothDescriptor> newDescriptors) {
43-
for(var d in descriptors) {
44-
for(var newD in newDescriptors){
45-
if(d.uuid == newD.uuid) {
46+
for (var d in descriptors) {
47+
for (var newD in newDescriptors) {
48+
if (d.uuid == newD.uuid) {
4649
d.value = newD.value;
4750
}
4851
}

lib/src/bluetooth_descriptor.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ class BluetoothDescriptor {
99

1010
final Guid uuid;
1111
final Guid serviceUuid; // The service that this descriptor belongs to.
12-
final Guid characteristicUuid; // The characteristic that this descriptor belongs to.
12+
final Guid
13+
characteristicUuid; // The characteristic that this descriptor belongs to.
1314
List<int> value;
1415

15-
BluetoothDescriptor({@required this.uuid, @required this.serviceUuid, @required this.characteristicUuid});
16+
BluetoothDescriptor(
17+
{@required this.uuid,
18+
@required this.serviceUuid,
19+
@required this.characteristicUuid});
1620

17-
BluetoothDescriptor.fromProto(protos.BluetoothDescriptor p) :
18-
uuid = new Guid(p.uuid),
19-
serviceUuid = new Guid(p.serviceUuid),
20-
characteristicUuid = new Guid(p.characteristicUuid),
21-
value = p.value;
22-
}
21+
BluetoothDescriptor.fromProto(protos.BluetoothDescriptor p)
22+
: uuid = new Guid(p.uuid),
23+
serviceUuid = new Guid(p.serviceUuid),
24+
characteristicUuid = new Guid(p.characteristicUuid),
25+
value = p.value;
26+
}

lib/src/bluetooth_device.dart

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class BluetoothDevice {
5151
..characteristicUuid = characteristic.uuid.toString()
5252
..serviceUuid = characteristic.serviceUuid.toString();
5353

54-
print('remoteId: ${id.toString()} characteristicUuid: ${characteristic.uuid.toString()} serviceUuid: ${characteristic.serviceUuid.toString()}');
54+
print(
55+
'remoteId: ${id.toString()} characteristicUuid: ${characteristic.uuid.toString()} serviceUuid: ${characteristic.serviceUuid.toString()}');
5556

5657
await FlutterBlue.instance._channel
5758
.invokeMethod('readCharacteristic', request.writeToBuffer());
@@ -82,8 +83,7 @@ class BluetoothDevice {
8283

8384
return await FlutterBlue.instance._descriptorReadChannel
8485
.receiveBroadcastStream()
85-
.map((buffer) =>
86-
new protos.ReadDescriptorResponse.fromBuffer(buffer))
86+
.map((buffer) => new protos.ReadDescriptorResponse.fromBuffer(buffer))
8787
.where((p) =>
8888
(p.request.remoteId == request.remoteId) &&
8989
(p.request.descriptorUuid == request.descriptorUuid) &&
@@ -99,40 +99,46 @@ class BluetoothDevice {
9999
/// guaranteed and will return immediately with success.
100100
/// [CharacteristicWriteType.withResponse]: the method will return after the
101101
/// write operation has either passed or failed.
102-
Future<Null> writeCharacteristic(BluetoothCharacteristic characteristic, List<int> value,
102+
Future<Null> writeCharacteristic(
103+
BluetoothCharacteristic characteristic, List<int> value,
103104
{CharacteristicWriteType type =
104105
CharacteristicWriteType.withoutResponse}) async {
105106
var request = protos.WriteCharacteristicRequest.create()
106107
..remoteId = id.toString()
107108
..characteristicUuid = characteristic.uuid.toString()
108109
..serviceUuid = characteristic.serviceUuid.toString()
109-
..writeType = protos.WriteCharacteristicRequest_WriteType.valueOf(type.index)
110+
..writeType =
111+
protos.WriteCharacteristicRequest_WriteType.valueOf(type.index)
110112
..value = value;
111113

112114
var result = await FlutterBlue.instance._channel
113115
.invokeMethod('writeCharacteristic', request.writeToBuffer());
114116

115-
if(type == CharacteristicWriteType.withoutResponse) {
117+
if (type == CharacteristicWriteType.withoutResponse) {
116118
return result;
117119
}
118120

119121
return await FlutterBlue.instance._methodStream
120-
.where((m) => m.method == "WriteCharacteristicResponse")
121-
.map((m) => m.arguments)
122-
.map((buffer) => new protos.WriteCharacteristicResponse.fromBuffer(buffer))
123-
.where((p) =>
124-
(p.request.remoteId == request.remoteId) &&
125-
(p.request.characteristicUuid == request.characteristicUuid) &&
126-
(p.request.serviceUuid == request.serviceUuid))
127-
.first
128-
.then((w) => w.success)
129-
.then((success) => (!success) ? throw new Exception('Failed to write the characteristic') : null)
130-
.then((_) => characteristic.value = value)
131-
.then((_) => null);
122+
.where((m) => m.method == "WriteCharacteristicResponse")
123+
.map((m) => m.arguments)
124+
.map((buffer) =>
125+
new protos.WriteCharacteristicResponse.fromBuffer(buffer))
126+
.where((p) =>
127+
(p.request.remoteId == request.remoteId) &&
128+
(p.request.characteristicUuid == request.characteristicUuid) &&
129+
(p.request.serviceUuid == request.serviceUuid))
130+
.first
131+
.then((w) => w.success)
132+
.then((success) => (!success)
133+
? throw new Exception('Failed to write the characteristic')
134+
: null)
135+
.then((_) => characteristic.value = value)
136+
.then((_) => null);
132137
}
133138

134139
/// Writes the value of a descriptor
135-
Future<Null> writeDescriptor(BluetoothDescriptor descriptor, List<int> value) async {
140+
Future<Null> writeDescriptor(
141+
BluetoothDescriptor descriptor, List<int> value) async {
136142
var request = protos.WriteDescriptorRequest.create()
137143
..remoteId = id.toString()
138144
..descriptorUuid = descriptor.uuid.toString()
@@ -148,13 +154,15 @@ class BluetoothDevice {
148154
.map((m) => m.arguments)
149155
.map((buffer) => new protos.WriteDescriptorResponse.fromBuffer(buffer))
150156
.where((p) =>
151-
(p.request.remoteId == request.remoteId) &&
152-
(p.request.descriptorUuid == request.descriptorUuid) &&
153-
(p.request.characteristicUuid == request.characteristicUuid) &&
154-
(p.request.serviceUuid == request.serviceUuid))
157+
(p.request.remoteId == request.remoteId) &&
158+
(p.request.descriptorUuid == request.descriptorUuid) &&
159+
(p.request.characteristicUuid == request.characteristicUuid) &&
160+
(p.request.serviceUuid == request.serviceUuid))
155161
.first
156162
.then((w) => w.success)
157-
.then((success) => (!success) ? throw new Exception('Failed to write the descriptor') : null)
163+
.then((success) => (!success)
164+
? throw new Exception('Failed to write the descriptor')
165+
: null)
158166
.then((_) => descriptor.value = value)
159167
.then((_) => null);
160168
}
@@ -168,24 +176,24 @@ class BluetoothDevice {
168176
..characteristicUuid = characteristic.uuid.toString()
169177
..enable = notify;
170178

171-
await FlutterBlue.instance._channel.invokeMethod('setNotification', request.writeToBuffer());
179+
await FlutterBlue.instance._channel
180+
.invokeMethod('setNotification', request.writeToBuffer());
172181

173182
return await FlutterBlue.instance._methodStream
174183
.where((m) => m.method == "SetNotificationResponse")
175184
.map((m) => m.arguments)
176-
.map((buffer) =>
177-
new protos.SetNotificationResponse.fromBuffer(buffer))
185+
.map((buffer) => new protos.SetNotificationResponse.fromBuffer(buffer))
178186
.where((p) =>
179-
(p.remoteId == request.remoteId) &&
180-
(p.characteristic.uuid == request.characteristicUuid) &&
181-
(p.characteristic.serviceUuid == request.serviceUuid))
187+
(p.remoteId == request.remoteId) &&
188+
(p.characteristic.uuid == request.characteristicUuid) &&
189+
(p.characteristic.serviceUuid == request.serviceUuid))
182190
.first
183191
.then((p) => new BluetoothCharacteristic.fromProto(p.characteristic))
184192
.then((c) {
185-
characteristic.updateDescriptors(c.descriptors);
186-
characteristic.value = c.value;
187-
return (c.isNotifying == notify);
188-
});
193+
characteristic.updateDescriptors(c.descriptors);
194+
characteristic.value = c.value;
195+
return (c.isNotifying == notify);
196+
});
189197
}
190198

191199
/// Notifies when the characteristic's value has changed.
@@ -199,17 +207,17 @@ class BluetoothDevice {
199207
.map((p) => new BluetoothCharacteristic.fromProto(p.characteristic))
200208
.where((c) => c.uuid == characteristic.uuid)
201209
.map((c) {
202-
characteristic.updateDescriptors(c.descriptors);
203-
characteristic.value = c.value;
204-
return c.value;
205-
});
210+
characteristic.updateDescriptors(c.descriptors);
211+
characteristic.value = c.value;
212+
return c.value;
213+
});
206214
}
207215

208216
/// The current connection state of the device
209-
Future<BluetoothDeviceState> get state =>
210-
FlutterBlue.instance._channel.invokeMethod('deviceState', id.toString())
211-
.then((buffer) => new protos.DeviceStateResponse.fromBuffer(buffer))
212-
.then((p) => BluetoothDeviceState.values[p.state.value]);
217+
Future<BluetoothDeviceState> get state => FlutterBlue.instance._channel
218+
.invokeMethod('deviceState', id.toString())
219+
.then((buffer) => new protos.DeviceStateResponse.fromBuffer(buffer))
220+
.then((p) => BluetoothDeviceState.values[p.state.value]);
213221

214222
/// Notifies when the device connection state has changed
215223
Stream<BluetoothDeviceState> onStateChanged() {

lib/src/bluetooth_service.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class BluetoothService {
2323
deviceId = new DeviceIdentifier(p.remoteId),
2424
isPrimary = p.isPrimary,
2525
characteristics = p.characteristics
26-
.map((c) => new BluetoothCharacteristic.fromProto(c)).toList(),
27-
includedServices =
28-
p.includedServices.map((s) => new BluetoothService.fromProto(s)).toList();
26+
.map((c) => new BluetoothCharacteristic.fromProto(c))
27+
.toList(),
28+
includedServices = p.includedServices
29+
.map((s) => new BluetoothService.fromProto(s))
30+
.toList();
2931
}

lib/src/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
part of flutter_blue;
66

7-
const NAMESPACE = 'plugins.pauldemarco.com/flutter_blue';
7+
const NAMESPACE = 'plugins.pauldemarco.com/flutter_blue';

0 commit comments

Comments
 (0)