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

49 lines
1.6 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\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: 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),
),
],
),
);
}