import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; const MethodChannel _settingsChannel = MethodChannel('abawo/settings'); Future openBluetoothSettings() async { if (!Platform.isAndroid) { return false; } try { return await _settingsChannel.invokeMethod('openBluetoothSettings') ?? false; } on PlatformException { return false; } } Future showBluetoothPairingRecoveryDialog(BuildContext context) { return showDialog( 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'), ), ], ), ); }