Files
abawo-bt-app/lib/util/bluetooth_settings.dart

49 lines
1.7 KiB
Dart

import 'dart:io';
import 'package:app_settings/app_settings.dart';
import 'package:flutter/material.dart';
Future<bool> openBluetoothSettings() async {
try {
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\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.';
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: Text(content),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Not now'),
),
FilledButton(
onPressed: () async {
Navigator.of(context).pop();
await openBluetoothSettings();
},
child: Text(settingsButtonLabel),
),
],
),
);
}