From 9ce00556ec7a3b8a652161514c9f656c6f801913 Mon Sep 17 00:00:00 2001 From: Leah Date: Wed, 11 Feb 2026 22:40:42 +0100 Subject: [PATCH] Add warning when bluetooth is off --- lib/l10n/app_en.arb | 3 ++ lib/screens/scanner_screen.dart | 55 +++++++++++++++++++++ untranslated.json | 86 ++++++++++++++++++++++++++++++++- 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 0c54be35..dcbc7cb4 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -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", diff --git a/lib/screens/scanner_screen.dart b/lib/screens/scanner_screen.dart index 75819a0a..2049dab7 100644 --- a/lib/screens/scanner_screen.dart +++ b/lib/screens/scanner_screen.dart @@ -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 { bool _changedNavigation = false; late final VoidCallback _connectionListener; + BluetoothAdapterState _bluetoothState = BluetoothAdapterState.unknown; + late StreamSubscription _bluetoothStateSubscription; @override void initState() { @@ -39,12 +43,22 @@ class _ScannerScreenState extends State { }; connector.addListener(_connectionListener); + + _bluetoothStateSubscription = + FlutterBluePlus.adapterState.listen((state) { + if (mounted) { + setState(() { + _bluetoothState = state; + }); + } + }); } @override void dispose() { final connector = Provider.of(context, listen: false); connector.removeListener(_connectionListener); + _bluetoothStateSubscription.cancel(); super.dispose(); } @@ -62,6 +76,10 @@ class _ScannerScreenState extends State { 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 { } } } + + 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, + ), + ), + ], + ), + ), + ], + ), + ); + } } diff --git a/untranslated.json b/untranslated.json index 9e26dfee..2b5dc439 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1 +1,85 @@ -{} \ No newline at end of file +{ + "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" + ] +}