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

45 lines
1.2 KiB
Dart

import 'dart:io';
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 {
return false;
}
}
Future<void> showBluetoothPairingRecoveryDialog(BuildContext context) {
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.',
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Not now'),
),
FilledButton(
onPressed: () async {
Navigator.of(context).pop();
await openBluetoothSettings();
},
child: const Text('Open Bluetooth settings'),
),
],
),
);
}