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
* Add `CentralController#getMaximumWriteLength` method.

View File

@ -347,8 +347,7 @@ class _PeripheralViewState extends State<PeripheralView> {
return;
}
const type = LogType.notify;
final value = hex.encode(eventArgs.value);
final log = Log(type, value);
final log = Log(type, eventArgs.value);
logs.value = [
...logs.value,
log,
@ -497,9 +496,10 @@ class _PeripheralViewState extends State<PeripheralView> {
}
final time = DateFormat.Hms().format(log.time);
final value = log.value;
final message = hex.encode(value);
return Text.rich(
TextSpan(
text: '[$type]',
text: '[$type:${value.length}]',
children: [
TextSpan(
text: ' $time: ',
@ -508,7 +508,7 @@ class _PeripheralViewState extends State<PeripheralView> {
),
),
TextSpan(
text: value,
text: message,
style: theme.textTheme.bodyMedium,
),
],
@ -641,8 +641,7 @@ class _PeripheralViewState extends State<PeripheralView> {
final value = await centralController
.readCharacteristic(characteristic);
const type = LogType.read;
final text = hex.encode(value);
final log = Log(type, text);
final log = Log(type, value);
logs.value = [...logs.value, log];
}
: null,
@ -660,7 +659,7 @@ class _PeripheralViewState extends State<PeripheralView> {
type: GattCharacteristicWriteType
.withResponse,
);
final log = Log(LogType.write, text);
final log = Log(LogType.write, value);
logs.value = [...logs.value, log];
}
: null,
@ -698,7 +697,7 @@ class _PeripheralViewState extends State<PeripheralView> {
class Log {
final DateTime time;
final LogType type;
final String value;
final Uint8List value;
Log(this.type, this.value) : time = DateTime.now();
@ -707,7 +706,8 @@ class Log {
final type = this.type.toString().split('.').last;
final formatter = DateFormat.Hms();
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: ".."
relative: true
source: path
version: "2.2.0"
version: "2.2.1"
bluetooth_low_energy_android:
dependency: transitive
description:
name: bluetooth_low_energy_android
sha256: fde30d9ef058f6859266a8e6d4218136958366de5978f69df2bb37d2b24679eb
sha256: "2098167f30a05cff40313fd49c459d326590b54dc6ea953cbe7ff145ce940e04"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
version: "2.2.1"
bluetooth_low_energy_darwin:
dependency: transitive
description:

View File

@ -1,6 +1,6 @@
name: 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
environment:
@ -11,7 +11,7 @@ dependencies:
flutter:
sdk: flutter
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_linux: ^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
* Add `CentralController#getMaximumWriteLength` method.

View File

@ -450,6 +450,10 @@ class MyCentralController(private val context: Context, binaryMessenger: BinaryM
gatt.close()
cachedGATTs.remove(deviceKey)
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)
if (discoverGattCallback != null) {
discoverGattCallback(Result.failure(error))

View File

@ -1,6 +1,6 @@
name: bluetooth_low_energy_android
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
environment: