Add warning when bluetooth is off

This commit is contained in:
Leah
2026-02-11 22:40:42 +01:00
parent 4995f5f380
commit 9ce00556ec
3 changed files with 143 additions and 1 deletions
+3
View File
@@ -66,6 +66,9 @@
},
"scanner_stop": "Stop",
"scanner_scan": "Scan",
"scanner_bluetoothOff": "Bluetooth is off",
"scanner_bluetoothOffMessage": "Please turn on Bluetooth to scan for devices",
"scanner_enableBluetooth": "Enable Bluetooth",
"device_quickSwitch": "Quick switch",
"device_meshcore": "MeshCore",
+55
View File
@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:provider/provider.dart';
@@ -18,6 +20,8 @@ class ScannerScreen extends StatefulWidget {
class _ScannerScreenState extends State<ScannerScreen> {
bool _changedNavigation = false;
late final VoidCallback _connectionListener;
BluetoothAdapterState _bluetoothState = BluetoothAdapterState.unknown;
late StreamSubscription<BluetoothAdapterState> _bluetoothStateSubscription;
@override
void initState() {
@@ -39,12 +43,22 @@ class _ScannerScreenState extends State<ScannerScreen> {
};
connector.addListener(_connectionListener);
_bluetoothStateSubscription =
FlutterBluePlus.adapterState.listen((state) {
if (mounted) {
setState(() {
_bluetoothState = state;
});
}
});
}
@override
void dispose() {
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
connector.removeListener(_connectionListener);
_bluetoothStateSubscription.cancel();
super.dispose();
}
@@ -62,6 +76,10 @@ class _ScannerScreenState extends State<ScannerScreen> {
builder: (context, connector, child) {
return Column(
children: [
// Bluetooth off warning
if (_bluetoothState != BluetoothAdapterState.on)
_bluetoothOffWarning(context),
// Status bar
_buildStatusBar(context, connector),
@@ -205,4 +223,41 @@ class _ScannerScreenState extends State<ScannerScreen> {
}
}
}
Widget _bluetoothOffWarning(BuildContext context) {
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
color: Colors.red.withValues(alpha: 0.15),
child: Row(
children: [
Icon(Icons.bluetooth_disabled, size: 24, color: Colors.red),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.l10n.scanner_bluetoothOff,
style: const TextStyle(
color: Colors.red,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
const SizedBox(height: 4),
Text(
context.l10n.scanner_bluetoothOffMessage,
style: TextStyle(
color: Colors.red.withValues(alpha: 0.85),
fontSize: 12,
),
),
],
),
),
],
),
);
}
}
+85 -1
View File
@@ -1 +1,85 @@
{}
{
"bg": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"de": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"es": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"fr": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"it": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"nl": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"pl": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"pt": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"ru": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"sk": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"sl": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"sv": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"uk": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
],
"zh": [
"scanner_bluetoothOff",
"scanner_bluetoothOffMessage",
"scanner_enableBluetooth"
]
}