Merge upstream/dev (2 commits) [upstream-sync]
This commit is contained in:
commit
b984e1d9a3
60 files changed
+989
-1472
No files matched your search
@@ -4,9 +4,8 @@ import 'package:provider/provider.dart';
|
||||
import '../connector/meshcore_connector.dart';
|
||||
import '../helpers/snack_bar_builder.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../screens/scanner_screen.dart';
|
||||
import '../screens/connect_screen.dart';
|
||||
import '../screens/settings_screen.dart';
|
||||
import '../screens/usb_screen.dart';
|
||||
import '../storage/last_radio_store.dart';
|
||||
import '../theme/theme_icons.dart';
|
||||
import '../utils/dialog_utils.dart';
|
||||
@@ -42,13 +41,15 @@ class _ConnectSheet extends StatelessWidget {
|
||||
void _chooseRadio(BuildContext context, LastRadio? lastRadio) {
|
||||
Navigator.of(context).pop();
|
||||
if (!hostContext.mounted) return;
|
||||
final usb =
|
||||
PlatformInfo.isWeb ||
|
||||
(lastRadio?.transport == LastRadio.transportUsb &&
|
||||
PlatformInfo.supportsUsbSerial);
|
||||
final transport = switch (lastRadio?.transport) {
|
||||
_ when PlatformInfo.isWeb => MeshCoreTransportType.usb,
|
||||
LastRadio.transportUsb => MeshCoreTransportType.usb,
|
||||
LastRadio.transportTcp => MeshCoreTransportType.tcp,
|
||||
_ => MeshCoreTransportType.bluetooth,
|
||||
};
|
||||
Navigator.of(hostContext).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => usb ? const UsbScreen() : const ScannerScreen(),
|
||||
builder: (_) => ConnectScreen(initialTransport: transport),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,51 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
|
||||
|
||||
import '../l10n/l10n.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'mesh_ui.dart';
|
||||
import 'signal_ui.dart';
|
||||
|
||||
/// A MeshCard-based row for displaying a scanned BLE device.
|
||||
/// Shows an AvatarCircle (router icon, deterministic hue from device name),
|
||||
/// device name, mono MAC address, mono RSSI dBm, and SignalBars on the right.
|
||||
/// While connecting, shows a small progress ring instead of signal bars.
|
||||
/// A MeshCard row for a radio to connect to: an AvatarCircle, the name, a
|
||||
/// mono id and, for a scanned BLE device, its signal ([rssi]) on the right.
|
||||
/// While connecting, shows a small progress ring instead of the signal.
|
||||
class DeviceTile extends StatelessWidget {
|
||||
final ScanResult scanResult;
|
||||
final String name;
|
||||
final String? id;
|
||||
final IconData icon;
|
||||
final Color? color;
|
||||
final int? rssi;
|
||||
final VoidCallback? onTap;
|
||||
final bool isConnecting;
|
||||
|
||||
const DeviceTile({
|
||||
super.key,
|
||||
required this.scanResult,
|
||||
required this.name,
|
||||
this.id,
|
||||
required this.icon,
|
||||
this.color,
|
||||
this.rssi,
|
||||
required this.onTap,
|
||||
this.isConnecting = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final device = scanResult.device;
|
||||
final rssi = scanResult.rssi;
|
||||
final name = device.platformName.isNotEmpty
|
||||
? device.platformName
|
||||
: scanResult.advertisementData.advName;
|
||||
final displayName = name.isNotEmpty
|
||||
? name
|
||||
: context.l10n.common_unknownDevice;
|
||||
final mac = device.remoteId.toString();
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
|
||||
final tier = rssi >= -60
|
||||
? 0
|
||||
: rssi >= -70
|
||||
? 1
|
||||
: rssi >= -80
|
||||
? 2
|
||||
: rssi >= -90
|
||||
? 3
|
||||
: 4;
|
||||
final signalUi = signalUiForStrengthTier(tier);
|
||||
final trailing = isConnecting
|
||||
? SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: scheme.primary,
|
||||
),
|
||||
)
|
||||
: rssi == null
|
||||
? null
|
||||
: _signal(rssi!);
|
||||
|
||||
return MeshCard(
|
||||
onTap: onTap == null
|
||||
@@ -57,7 +54,7 @@ class DeviceTile extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
AvatarCircle(name: displayName, size: 42, icon: Icons.router),
|
||||
AvatarCircle(name: name, size: 42, icon: icon, color: color),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
@@ -65,7 +62,7 @@ class DeviceTile extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
displayName,
|
||||
name,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: scheme.onSurface,
|
||||
@@ -73,48 +70,53 @@ class DeviceTile extends StatelessWidget {
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
mac,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
if (id != null) ...[
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
id!,
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
if (isConnecting)
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: scheme.primary,
|
||||
),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Icon(signalUi.icon, size: 20, color: signalUi.color),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
'$rssi dBm',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: signalUi.color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (trailing != null) ...[const SizedBox(width: 12), trailing],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _signal(int rssi) {
|
||||
final tier = rssi >= -60
|
||||
? 0
|
||||
: rssi >= -70
|
||||
? 1
|
||||
: rssi >= -80
|
||||
? 2
|
||||
: rssi >= -90
|
||||
? 3
|
||||
: 4;
|
||||
final signalUi = signalUiForStrengthTier(tier);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Icon(signalUi.icon, size: 20, color: signalUi.color),
|
||||
const SizedBox(height: 3),
|
||||
Text(
|
||||
'$rssi dBm',
|
||||
style: MeshTheme.mono(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: signalUi.color,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,12 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../services/node_banner_service.dart';
|
||||
import '../theme/mesh_theme.dart';
|
||||
import 'settings_reveal.dart';
|
||||
|
||||
/// Bottom banner on the connect screen pointing new users at a node to buy.
|
||||
/// Its link (and optionally its text) comes from the `_banner` DNS TXT
|
||||
/// record; it stays hidden until that loads, and when the lookup fails or the
|
||||
/// record turns it off.
|
||||
/// record turns it off. Close hides it until the screen closes.
|
||||
class GetNodeBanner extends StatefulWidget {
|
||||
final Future<NodeBannerConfig?> Function()? loadConfig;
|
||||
|
||||
@@ -20,6 +21,7 @@ class GetNodeBanner extends StatefulWidget {
|
||||
|
||||
class _GetNodeBannerState extends State<GetNodeBanner> {
|
||||
NodeBannerConfig? _config;
|
||||
bool _closed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -32,17 +34,34 @@ class _GetNodeBannerState extends State<GetNodeBanner> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final config = _config;
|
||||
if (config == null) return const SizedBox.shrink();
|
||||
// A landscape phone has no room for it next to the screen's content.
|
||||
final roomy = MediaQuery.sizeOf(context).height >= 480;
|
||||
// The bottom inset stays reserved while hidden, so the screen's content
|
||||
// keeps clear of the system bar.
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: RevealOnEnable(
|
||||
visible: config != null && !_closed && roomy,
|
||||
child: config == null
|
||||
? const SizedBox.shrink()
|
||||
: _buildBanner(context, config),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBanner(BuildContext context, NodeBannerConfig config) {
|
||||
final l10n = context.l10n;
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final ink = scheme.onPrimaryContainer;
|
||||
void open() => launchUrl(config.url, mode: LaunchMode.externalApplication);
|
||||
|
||||
return SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(12, 4, 12, 12),
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 12),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.sizeOf(context).height * 0.4,
|
||||
),
|
||||
child: Material(
|
||||
color: scheme.primaryContainer,
|
||||
shape: RoundedRectangleBorder(
|
||||
@@ -52,56 +71,62 @@ class _GetNodeBannerState extends State<GetNodeBanner> {
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: open,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 12, 14, 10),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(14, 2, 2, 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.router_outlined,
|
||||
size: 28,
|
||||
color: scheme.onPrimaryContainer,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Icon(Icons.router_outlined, size: 24, color: ink),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
config.title ?? l10n.scanner_getNodeTitle,
|
||||
style: textTheme.titleMedium?.copyWith(
|
||||
color: scheme.onPrimaryContainer,
|
||||
color: ink,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.close, color: ink),
|
||||
tooltip: l10n.common_close,
|
||||
onPressed: () => setState(() => _closed = true),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
config.body ?? l10n.scanner_getNodeBody,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onPrimaryContainer,
|
||||
height: 1.35,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: FilledButton.icon(
|
||||
onPressed: open,
|
||||
icon: const Icon(Icons.shopping_cart_outlined, size: 22),
|
||||
label: Text(config.action ?? l10n.scanner_getNodeAction),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Center(
|
||||
child: Text(
|
||||
l10n.scanner_getNodeDisclosure,
|
||||
textAlign: TextAlign.center,
|
||||
style: textTheme.bodySmall?.copyWith(
|
||||
color: scheme.onPrimaryContainer.withValues(alpha: 0.8),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
config.body ?? l10n.scanner_getNodeBody,
|
||||
style: textTheme.bodyMedium?.copyWith(
|
||||
color: ink,
|
||||
height: 1.35,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FilledButton.icon(
|
||||
onPressed: open,
|
||||
icon: const Icon(Icons.shopping_cart_outlined),
|
||||
label: Text(
|
||||
config.action ?? l10n.scanner_getNodeAction,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
l10n.scanner_getNodeDisclosure,
|
||||
textAlign: TextAlign.center,
|
||||
style: textTheme.bodySmall?.copyWith(
|
||||
color: ink.withValues(alpha: 0.8),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user