Skip to content

Commit 487d98e

Browse files
authored
Stop notifying of value changes when a write happens (pauldemarco#526)
* Stop writes from triggering value changes. Fixes #311, #378, #351. * Read after write to automatically update the UI.
1 parent 5e15126 commit 487d98e

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

example/lib/main.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,14 @@ class DeviceScreen extends StatelessWidget {
176176
(c) => CharacteristicTile(
177177
characteristic: c,
178178
onReadPressed: () => c.read(),
179-
onWritePressed: () => c.write(_getRandomBytes()),
180-
onNotificationPressed: () =>
181-
c.setNotifyValue(!c.isNotifying),
179+
onWritePressed: () async {
180+
await c.write(_getRandomBytes(), withoutResponse: true);
181+
await c.read();
182+
},
183+
onNotificationPressed: () async {
184+
await c.setNotifyValue(!c.isNotifying);
185+
await c.read();
186+
},
182187
descriptorTiles: c.descriptors
183188
.map(
184189
(d) => DescriptorTile(

lib/src/bluetooth_characteristic.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ class BluetoothCharacteristic {
5454
.map((c) {
5555
// Update the characteristic with the new values
5656
_updateDescriptors(c.descriptors);
57-
// _value.add(c.lastValue);
58-
// print('c.lastValue: ${c.lastValue}');
5957
return c;
6058
});
6159

@@ -123,7 +121,6 @@ class BluetoothCharacteristic {
123121
.invokeMethod('writeCharacteristic', request.writeToBuffer());
124122

125123
if (type == CharacteristicWriteType.withoutResponse) {
126-
_value.add(value);
127124
return result;
128125
}
129126

@@ -141,7 +138,6 @@ class BluetoothCharacteristic {
141138
.then((success) => (!success)
142139
? throw new Exception('Failed to write the characteristic')
143140
: null)
144-
.then((_) => _value.add(value))
145141
.then((_) => null);
146142
}
147143

@@ -168,7 +164,6 @@ class BluetoothCharacteristic {
168164
.then((p) => new BluetoothCharacteristic.fromProto(p.characteristic))
169165
.then((c) {
170166
_updateDescriptors(c.descriptors);
171-
_value.add(c.lastValue);
172167
return (c.isNotifying == notify);
173168
});
174169
}

0 commit comments

Comments
 (0)