feat: better pairing broken notification

This commit is contained in:
2026-05-05 21:06:11 +02:00
parent 230a6838e0
commit 4fceb0c690
5 changed files with 39 additions and 4 deletions

View File

@ -732,6 +732,11 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
} }
if (result.isErr()) { if (result.isErr()) {
if (isBluetoothPairingRecoveryError(result.unwrapErr())) {
await showBluetoothPairingRecoveryDialog(context);
return;
}
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text( content: Text(

View File

@ -116,12 +116,11 @@ class _ConnectDevicePageState extends ConsumerState<ConnectDevicePage> {
} }
break; break;
case Err(:final v): case Err(:final v):
final error = v.toString(); if (isBluetoothPairingRecoveryError(v)) {
if (error.toLowerCase().contains('disconnected')) {
await showBluetoothPairingRecoveryDialog(context); await showBluetoothPairingRecoveryDialog(context);
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Connection unsuccessful:\n$error')), SnackBar(content: Text('Connection unsuccessful:\n$v')),
); );
} }
break; break;

View File

@ -8,6 +8,7 @@ import 'package:abawo_bt_app/model/firmware_file_selection.dart';
import 'package:abawo_bt_app/model/shifter_types.dart'; import 'package:abawo_bt_app/model/shifter_types.dart';
import 'package:abawo_bt_app/pages/bootloader_recovery_update_page.dart'; import 'package:abawo_bt_app/pages/bootloader_recovery_update_page.dart';
import 'package:abawo_bt_app/service/firmware_file_selection_service.dart'; import 'package:abawo_bt_app/service/firmware_file_selection_service.dart';
import 'package:abawo_bt_app/util/bluetooth_settings.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart' import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'
show DiscoveredDevice, ScanMode, Uuid; show DiscoveredDevice, ScanMode, Uuid;
@ -586,6 +587,8 @@ class _SavedDevicesListState extends ConsumerState<_SavedDevicesList> {
} }
context.push('/device/${device.deviceAddress}'); context.push('/device/${device.deviceAddress}');
} else if (isBluetoothPairingRecoveryError(result.unwrapErr())) {
await showBluetoothPairingRecoveryDialog(context);
} else { } else {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( const SnackBar(

View File

@ -3,6 +3,10 @@ import 'dart:io';
import 'package:app_settings/app_settings.dart'; import 'package:app_settings/app_settings.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
bool isBluetoothPairingRecoveryError(Object error) {
return error.toString().toLowerCase().contains('disconnected');
}
Future<bool> openBluetoothSettings() async { Future<bool> openBluetoothSettings() async {
try { try {
if (Platform.isAndroid) { if (Platform.isAndroid) {
@ -23,7 +27,8 @@ Future<void> showBluetoothPairingRecoveryDialog(BuildContext context) {
final content = isIOS final content = isIOS
? 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nGo to Settings, then Bluetooth, then forget this device. After that, come back and connect again.\n\nOr press Open Settings below. From the app settings page, press Back twice to reach Bluetooth settings, then forget this device.' ? 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nGo to Settings, then Bluetooth, then forget this device. After that, come back and connect again.\n\nOr press Open Settings below. From the app settings page, press Back twice to reach Bluetooth settings, then forget this device.'
: 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nOpen Bluetooth settings, remove/forget this device, then come back and connect again.'; : 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nOpen Bluetooth settings, remove/forget this device, then come back and connect again.';
final settingsButtonLabel = isIOS ? 'Open Settings' : 'Open Bluetooth settings'; final settingsButtonLabel =
isIOS ? 'Open Settings' : 'Open Bluetooth settings';
return showDialog<void>( return showDialog<void>(
context: context, context: context,

View File

@ -0,0 +1,23 @@
import 'package:abawo_bt_app/util/bluetooth_settings.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('isBluetoothPairingRecoveryError', () {
test('detects immediate disconnect connection failures', () {
expect(
isBluetoothPairingRecoveryError(
'Failed to connect to device-id: disconnected',
),
isTrue,
);
});
test('does not classify generic connection failures as pairing recovery',
() {
expect(
isBluetoothPairingRecoveryError('Timed out connecting to device-id'),
isFalse,
);
});
});
}