mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-08-01 08:05:55 +10:00
Add warning when bluetooth is off
This commit is contained in:
@@ -66,6 +66,9 @@
|
|||||||
},
|
},
|
||||||
"scanner_stop": "Stop",
|
"scanner_stop": "Stop",
|
||||||
"scanner_scan": "Scan",
|
"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_quickSwitch": "Quick switch",
|
||||||
"device_meshcore": "MeshCore",
|
"device_meshcore": "MeshCore",
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -18,6 +20,8 @@ class ScannerScreen extends StatefulWidget {
|
|||||||
class _ScannerScreenState extends State<ScannerScreen> {
|
class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
bool _changedNavigation = false;
|
bool _changedNavigation = false;
|
||||||
late final VoidCallback _connectionListener;
|
late final VoidCallback _connectionListener;
|
||||||
|
BluetoothAdapterState _bluetoothState = BluetoothAdapterState.unknown;
|
||||||
|
late StreamSubscription<BluetoothAdapterState> _bluetoothStateSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -39,12 +43,22 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
connector.addListener(_connectionListener);
|
connector.addListener(_connectionListener);
|
||||||
|
|
||||||
|
_bluetoothStateSubscription =
|
||||||
|
FlutterBluePlus.adapterState.listen((state) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_bluetoothState = state;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
connector.removeListener(_connectionListener);
|
connector.removeListener(_connectionListener);
|
||||||
|
_bluetoothStateSubscription.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +76,10 @@ class _ScannerScreenState extends State<ScannerScreen> {
|
|||||||
builder: (context, connector, child) {
|
builder: (context, connector, child) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
// Bluetooth off warning
|
||||||
|
if (_bluetoothState != BluetoothAdapterState.on)
|
||||||
|
_bluetoothOffWarning(context),
|
||||||
|
|
||||||
// Status bar
|
// Status bar
|
||||||
_buildStatusBar(context, connector),
|
_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
@@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user