fix(ios): open settings from pairing recovery

This commit is contained in:
2026-04-28 20:06:10 +02:00
parent 2e7c10f87d
commit 9922b90f49
5 changed files with 29 additions and 43 deletions

View File

@ -1,31 +1,35 @@
import 'dart:io';
import 'package:app_settings/app_settings.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
const MethodChannel _settingsChannel = MethodChannel('abawo/settings');
Future<bool> openBluetoothSettings() async {
if (!Platform.isAndroid) {
return false;
}
try {
return await _settingsChannel.invokeMethod<bool>('openBluetoothSettings') ??
false;
} on PlatformException {
if (Platform.isAndroid) {
await AppSettings.openAppSettings(type: AppSettingsType.bluetooth);
} else if (Platform.isIOS) {
await AppSettings.openAppSettings();
} else {
return false;
}
return true;
} catch (_) {
return false;
}
}
Future<void> showBluetoothPairingRecoveryDialog(BuildContext context) {
final isIOS = Platform.isIOS;
final content = isIOS
? 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nOn iOS, open Settings, go to Bluetooth, 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';
return showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: const Text('Bluetooth pairing may be broken'),
content: const Text(
'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.',
),
content: Text(content),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
@ -36,7 +40,7 @@ Future<void> showBluetoothPairingRecoveryDialog(BuildContext context) {
Navigator.of(context).pop();
await openBluetoothSettings();
},
child: const Text('Open Bluetooth settings'),
child: Text(settingsButtonLabel),
),
],
),