@@ -16,14 +16,16 @@ abstract class _PeripheralMetadata {
1616class Peripheral {
1717 static const int NO_MTU_NEGOTIATION = 0 ;
1818 ManagerForPeripheral _manager;
19+ TransactionIdGenerator _transactionIdGenerator;
1920
2021 String name;
2122 String identifier;
2223
23- Peripheral .fromJson (Map <String , dynamic > json, ManagerForPeripheral manager)
24+ Peripheral .fromJson (Map <String , dynamic > json, ManagerForPeripheral manager, { TransactionIdGenerator transactionIdGenerator = const TransactionIdGenerator ()} )
2425 : _manager = manager,
2526 name = json[_PeripheralMetadata .name],
26- identifier = json[_PeripheralMetadata .identifier];
27+ identifier = json[_PeripheralMetadata .identifier],
28+ _transactionIdGenerator = transactionIdGenerator;
2729
2830 /// Connects to the peripheral.
2931 ///
@@ -82,7 +84,7 @@ class Peripheral {
8284 /// Optional [transactionId] could be used to cancel operation.
8385 Future <void > discoverAllServicesAndCharacteristics ({String transactionId}) =>
8486 _manager.discoverAllServicesAndCharacteristics (
85- this , transactionId ?? TransactionIdGenerator .getNextId ());
87+ this , transactionId ?? _transactionIdGenerator .getNextId ());
8688
8789 /// Returns a list of [Service] s of this peripheral.
8890 ///
@@ -103,7 +105,7 @@ class Peripheral {
103105 ///
104106 /// Optional [transactionId] could be used to cancel operation.
105107 Future <int > rssi ({String transactionId}) =>
106- _manager.rssi (this , transactionId ?? TransactionIdGenerator .getNextId ());
108+ _manager.rssi (this , transactionId ?? _transactionIdGenerator .getNextId ());
107109
108110 /// Requests new MTU value for current connection and return the negotiation
109111 /// result on Android, reads MTU on iOS.
@@ -118,7 +120,7 @@ class Peripheral {
118120 /// If MTU has been requested in [connect()] this method will end with [BleError] .
119121 Future <int > requestMtu (int mtu, {String transactionId}) =>
120122 _manager.requestMtu (
121- this , mtu, transactionId ?? TransactionIdGenerator .getNextId ());
123+ this , mtu, transactionId ?? _transactionIdGenerator .getNextId ());
122124
123125 /// Reads value of [Characteristic] matching specified UUIDs.
124126 ///
@@ -135,7 +137,7 @@ class Peripheral {
135137 this ,
136138 serviceUuid,
137139 characteristicUuid,
138- transactionId ?? TransactionIdGenerator .getNextId (),
140+ transactionId ?? _transactionIdGenerator .getNextId (),
139141 );
140142
141143 /// Writes value of [Characteristic] matching specified UUIDs.
@@ -157,7 +159,7 @@ class Peripheral {
157159 characteristicUuid,
158160 value,
159161 withResponse,
160- transactionId ?? TransactionIdGenerator .getNextId (),
162+ transactionId ?? _transactionIdGenerator .getNextId (),
161163 );
162164
163165 /// Returns a list of [Descriptor] s for [Characteristic] matching specified UUIDs.
@@ -191,7 +193,7 @@ class Peripheral {
191193 serviceUuid,
192194 characteristicUuid,
193195 descriptorUuid,
194- transactionId ?? TransactionIdGenerator .getNextId (),
196+ transactionId ?? _transactionIdGenerator .getNextId (),
195197 );
196198
197199 /// Writes value of [Descriptor] matching specified UUIDs.
@@ -214,7 +216,7 @@ class Peripheral {
214216 characteristicUuid,
215217 descriptorUuid,
216218 value,
217- transactionId ?? TransactionIdGenerator .getNextId (),
219+ transactionId ?? _transactionIdGenerator .getNextId (),
218220 );
219221
220222 /// Returns a stream of notifications/indications from [Characteristic]
@@ -236,7 +238,7 @@ class Peripheral {
236238 this ,
237239 serviceUuid,
238240 characteristicUuid,
239- transactionId ?? TransactionIdGenerator .getNextId (),
241+ transactionId ?? _transactionIdGenerator .getNextId (),
240242 );
241243
242244 @override
0 commit comments