Files
meshcore-open/lib/widgets/get_node_banner.dart
T
celsoazevedoandClaude Opus 5.5 9104b4a60a Connect a radio: one page with Bluetooth, USB and TCP tabs
Replace the scanner, USB and TCP screens with one page and a tab for
each, so the design and the connection options are consistent. Fixes
#699, where the USB screen's Bluetooth button went back to the main
screens instead of the scanner.

The "Need a new node?" banner shows on every tab, with a close button
that hides it until the page is opened again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 08:57:32 +00:00

141 lines
5.1 KiB
Dart

import 'package:flutter/material.dart';
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. Close hides it until the screen closes.
class GetNodeBanner extends StatefulWidget {
final Future<NodeBannerConfig?> Function()? loadConfig;
const GetNodeBanner({super.key, this.loadConfig});
@override
State<GetNodeBanner> createState() => _GetNodeBannerState();
}
class _GetNodeBannerState extends State<GetNodeBanner> {
NodeBannerConfig? _config;
bool _closed = false;
@override
void initState() {
super.initState();
(widget.loadConfig ?? NodeBannerService().load)().then((config) {
if (mounted && config != null) setState(() => _config = config);
});
}
@override
Widget build(BuildContext context) {
final config = _config;
// 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 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(
borderRadius: BorderRadius.circular(MeshRadii.md),
side: BorderSide(color: scheme.primary.withValues(alpha: 0.4)),
),
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: open,
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: 24, color: ink),
const SizedBox(width: 12),
Expanded(
child: Text(
config.title ?? l10n.scanner_getNodeTitle,
style: textTheme.titleMedium?.copyWith(
color: ink,
fontWeight: FontWeight.w700,
),
),
),
IconButton(
icon: Icon(Icons.close, color: ink),
tooltip: l10n.common_close,
onPressed: () => setState(() => _closed = true),
),
],
),
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),
),
),
],
),
),
],
),
),
),
),
),
);
}
}