fix: 修复 getMaximumWriteLength 断开时未回调结果的问题 (#15)

This commit is contained in:
Mr剑侠客
2023-09-11 14:13:43 +08:00
committed by GitHub
parent 78bcb88563
commit 073c2b9a2e
7 changed files with 27 additions and 15 deletions

View File

@ -1,3 +1,7 @@
## 2.2.1
* `Android` Fix the issue that `CentralController#getMaximumWriteLength` may throw.
## 2.2.0 ## 2.2.0
* Add `CentralController#getMaximumWriteLength` method. * Add `CentralController#getMaximumWriteLength` method.

View File

@ -347,8 +347,7 @@ class _PeripheralViewState extends State<PeripheralView> {
return; return;
} }
const type = LogType.notify; const type = LogType.notify;
final value = hex.encode(eventArgs.value); final log = Log(type, eventArgs.value);
final log = Log(type, value);
logs.value = [ logs.value = [
...logs.value, ...logs.value,
log, log,
@ -497,9 +496,10 @@ class _PeripheralViewState extends State<PeripheralView> {
} }
final time = DateFormat.Hms().format(log.time); final time = DateFormat.Hms().format(log.time);
final value = log.value; final value = log.value;
final message = hex.encode(value);
return Text.rich( return Text.rich(
TextSpan( TextSpan(
text: '[$type]', text: '[$type:${value.length}]',
children: [ children: [
TextSpan( TextSpan(
text: ' $time: ', text: ' $time: ',
@ -508,7 +508,7 @@ class _PeripheralViewState extends State<PeripheralView> {
), ),
), ),
TextSpan( TextSpan(
text: value, text: message,
style: theme.textTheme.bodyMedium, style: theme.textTheme.bodyMedium,
), ),
], ],
@ -641,8 +641,7 @@ class _PeripheralViewState extends State<PeripheralView> {
final value = await centralController final value = await centralController
.readCharacteristic(characteristic); .readCharacteristic(characteristic);
const type = LogType.read; const type = LogType.read;
final text = hex.encode(value); final log = Log(type, value);
final log = Log(type, text);
logs.value = [...logs.value, log]; logs.value = [...logs.value, log];
} }
: null, : null,
@ -660,7 +659,7 @@ class _PeripheralViewState extends State<PeripheralView> {
type: GattCharacteristicWriteType type: GattCharacteristicWriteType
.withResponse, .withResponse,
); );
final log = Log(LogType.write, text); final log = Log(LogType.write, value);
logs.value = [...logs.value, log]; logs.value = [...logs.value, log];
} }
: null, : null,
@ -698,7 +697,7 @@ class _PeripheralViewState extends State<PeripheralView> {
class Log { class Log {
final DateTime time; final DateTime time;
final LogType type; final LogType type;
final String value; final Uint8List value;
Log(this.type, this.value) : time = DateTime.now(); Log(this.type, this.value) : time = DateTime.now();
@ -707,7 +706,8 @@ class Log {
final type = this.type.toString().split('.').last; final type = this.type.toString().split('.').last;
final formatter = DateFormat.Hms(); final formatter = DateFormat.Hms();
final time = formatter.format(this.time); final time = formatter.format(this.time);
return '[$type]$time: $value'; final message = hex.encode(value);
return '[$type]$time: $message';
} }
} }

View File

@ -23,15 +23,15 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "2.2.0" version: "2.2.1"
bluetooth_low_energy_android: bluetooth_low_energy_android:
dependency: transitive dependency: transitive
description: description:
name: bluetooth_low_energy_android name: bluetooth_low_energy_android
sha256: fde30d9ef058f6859266a8e6d4218136958366de5978f69df2bb37d2b24679eb sha256: "2098167f30a05cff40313fd49c459d326590b54dc6ea953cbe7ff145ce940e04"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.2.0" version: "2.2.1"
bluetooth_low_energy_darwin: bluetooth_low_energy_darwin:
dependency: transitive dependency: transitive
description: description:

View File

@ -1,6 +1,6 @@
name: bluetooth_low_energy name: bluetooth_low_energy
description: A Flutter plugin for controlling the bluetooth low energy. description: A Flutter plugin for controlling the bluetooth low energy.
version: 2.2.0 version: 2.2.1
homepage: https://github.com/yanshouwang/bluetooth_low_energy homepage: https://github.com/yanshouwang/bluetooth_low_energy
environment: environment:
@ -11,7 +11,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
bluetooth_low_energy_platform_interface: ^2.2.0 bluetooth_low_energy_platform_interface: ^2.2.0
bluetooth_low_energy_android: ^2.2.0 bluetooth_low_energy_android: ^2.2.1
bluetooth_low_energy_darwin: ^2.2.0 bluetooth_low_energy_darwin: ^2.2.0
bluetooth_low_energy_linux: ^2.2.0 bluetooth_low_energy_linux: ^2.2.0
bluetooth_low_energy_windows: ^2.2.0 bluetooth_low_energy_windows: ^2.2.0

View File

@ -1,3 +1,7 @@
## 2.2.1
* Fix the issue that `CentralController#getMaximumWriteLength` may throw.
## 2.2.0 ## 2.2.0
* Add `CentralController#getMaximumWriteLength` method. * Add `CentralController#getMaximumWriteLength` method.

View File

@ -450,6 +450,10 @@ class MyCentralController(private val context: Context, binaryMessenger: BinaryM
gatt.close() gatt.close()
cachedGATTs.remove(deviceKey) cachedGATTs.remove(deviceKey)
val error = IllegalStateException("GATT is disconnected with status: $status") val error = IllegalStateException("GATT is disconnected with status: $status")
val getMaximumWriteLengthCallback = getMaximumWriteLengthCallbacks.remove(deviceKey)
if (getMaximumWriteLengthCallback != null) {
getMaximumWriteLengthCallback(Result.failure(error))
}
val discoverGattCallback = discoverGattCallbacks.remove(deviceKey) val discoverGattCallback = discoverGattCallbacks.remove(deviceKey)
if (discoverGattCallback != null) { if (discoverGattCallback != null) {
discoverGattCallback(Result.failure(error)) discoverGattCallback(Result.failure(error))

View File

@ -1,6 +1,6 @@
name: bluetooth_low_energy_android name: bluetooth_low_energy_android
description: Android implementation of the bluetooth_low_energy plugin. description: Android implementation of the bluetooth_low_energy plugin.
version: 2.2.0 version: 2.2.1
homepage: https://github.com/yanshouwang/bluetooth_low_energy homepage: https://github.com/yanshouwang/bluetooth_low_energy
environment: environment: