mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-21 08:11:06 +10:00
Enhance USB functionality by adding request port label management and platform support checks
This commit is contained in:
committed by
just-stuff-tm
parent
ca5784f3f8
commit
781090243c
@@ -3,6 +3,7 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
import '../utils/platform_info.dart';
|
||||
import 'scanner_screen.dart';
|
||||
import 'usb_screen.dart';
|
||||
|
||||
@@ -14,6 +15,7 @@ class ConnectionChoiceScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = context.l10n;
|
||||
final theme = Theme.of(context);
|
||||
final usbSupported = PlatformInfo.supportsUsbSerial;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: FittedBox(
|
||||
@@ -82,14 +84,18 @@ class ConnectionChoiceScreen extends StatelessWidget {
|
||||
label: l10n.connectionChoiceUsbLabel,
|
||||
color: theme.colorScheme.primaryContainer,
|
||||
iconColor: theme.colorScheme.onPrimaryContainer,
|
||||
onPressed: () {
|
||||
debugPrint(
|
||||
'ConnectionChoiceScreen: USB selected, opening UsbScreen',
|
||||
);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const UsbScreen()),
|
||||
);
|
||||
},
|
||||
onPressed: usbSupported
|
||||
? () {
|
||||
debugPrint(
|
||||
'ConnectionChoiceScreen: USB selected, opening UsbScreen',
|
||||
);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const UsbScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
SizedBox(height: gap),
|
||||
@@ -133,7 +139,7 @@ class _ConnectionMethodButton extends StatelessWidget {
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final VoidCallback onPressed;
|
||||
final VoidCallback? onPressed;
|
||||
final Color color;
|
||||
final Color iconColor;
|
||||
|
||||
|
||||
@@ -61,6 +61,12 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
unawaited(_loadPorts());
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_connector.setUsbRequestPortLabel(context.l10n.usbScreenStatus);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_connector.removeListener(_connectionListener);
|
||||
@@ -389,6 +395,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
|
||||
Future<void> _loadPorts() async {
|
||||
if (!mounted) return;
|
||||
_connector.setUsbRequestPortLabel(context.l10n.usbScreenStatus);
|
||||
|
||||
setState(() {
|
||||
_isLoadingPorts = true;
|
||||
@@ -425,6 +432,7 @@ class _UsbScreenState extends State<UsbScreen> {
|
||||
if (selectedPort == null || selectedPort.isEmpty) {
|
||||
return;
|
||||
}
|
||||
_connector.setUsbRequestPortLabel(context.l10n.usbScreenStatus);
|
||||
if (_connector.state != MeshCoreConnectionState.disconnected) {
|
||||
setState(() {
|
||||
_isConnecting = false;
|
||||
|
||||
Reference in New Issue
Block a user