mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-12-04 12:42:18 +01:00
feat(network-test): live-test card, and fix the page's phone layout
Two things from the design that the first pass left out. The live test now gets the card the design gives it, instead of a bullet list inside a row. It is the only check with a duration and the only one the rider takes part in, so while it runs it takes over its section: a tinted head with the ask and a mono countdown, a progress bar, and the four-step path the trainer app walks — found us, looked up the details, asked for our address, connected — with the connector turning green behind each step that has happened. WatchProgress carries the window now so the bar does not hard-code the probe's 60s; the two would drift the moment either moved. The phone layout was broken, and by me. Rendering the page at 320/360/390 and at 1.3x/1.6x text produced nine layout errors at every size: RenderFlex children have non-zero flex but incoming height constraints are unbounded The footer used a Flex that flips to vertical when narrow. A Flexible keeps flex:1 whichever fit it is handed, and a flexed child inside this page's SingleChildScrollView has no bounded height to flex against — the eight "RenderBox was not laid out" errors after it were all fallout from that one. Replaced with an explicit arrangement: a Row with Expanded when there is room, a plain Column when there is not. Nine errors to zero at every width and text scale, and that sweep is now a test rather than something I ran once — it drives the page and the live card across three widths and two text scales and asserts no layout errors at all. Not verified by eye: the live card cannot be captured, because its spinner animates forever and pumpAndSettle never returns. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import 'package:bike_control/widgets/logviewer.dart';
|
||||
import 'package:bike_control/widgets/menu.dart' show debugText;
|
||||
import 'package:bike_control/widgets/network_check_row.dart';
|
||||
import 'package:bike_control/widgets/network_test/network_gauge.dart';
|
||||
import 'package:bike_control/widgets/network_test/network_live_test_card.dart';
|
||||
import 'package:bike_control/widgets/network_test/network_tokens.dart';
|
||||
import 'package:bike_control/widgets/ui/small_progress_indicator.dart';
|
||||
import 'package:bike_control/widgets/ui/toast.dart';
|
||||
@@ -408,6 +409,26 @@ class _NetworkTroubleshootingPageState extends State<NetworkTroubleshootingPage>
|
||||
|
||||
final sections = <Widget>[];
|
||||
for (final group in NetworkCheckGroup.values) {
|
||||
// The guided watch is the one check the rider participates in, and the
|
||||
// only one with a duration. While it runs it takes over its section as a
|
||||
// card of its own rather than a row, so the ask and the countdown are
|
||||
// the thing on screen.
|
||||
final watch = state.watch;
|
||||
if (group == NetworkCheckGroup.liveTest && watch != null && running == NetworkCheckId.guidedWatch) {
|
||||
sections
|
||||
..add(const Gap(18))
|
||||
..add(_GroupLabel(text: _groupLabel(l10n, group)))
|
||||
..add(const Gap(8))
|
||||
..add(
|
||||
NetworkLiveTestCard(
|
||||
key: const ValueKey('check-guidedWatch-running'),
|
||||
watch: watch,
|
||||
appName: core.settings.getTrainerApp()?.name,
|
||||
onSkip: _engine?.cancelWatch,
|
||||
),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
final rows = <Widget>[
|
||||
for (final check in done)
|
||||
if (_groupOf(check.id) == group)
|
||||
@@ -556,21 +577,22 @@ class _NetworkTroubleshootingPageState extends State<NetworkTroubleshootingPage>
|
||||
return _Panel(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 18),
|
||||
// Deliberately two arrangements rather than one Flex that flips axis:
|
||||
// a Flexible keeps flex:1 whichever fit it is given, and a vertical
|
||||
// Flex with a flexed child inside this page's SingleChildScrollView is
|
||||
// an unbounded-height constraint error, not a layout.
|
||||
child: Flex(
|
||||
direction: MediaQuery.sizeOf(context).width < 640 ? Axis.vertical : Axis.horizontal,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Flexible(
|
||||
fit: MediaQuery.sizeOf(context).width < 640 ? FlexFit.loose : FlexFit.tight,
|
||||
child: Column(
|
||||
Flexible(child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.networkFooterTitle, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
|
||||
const Gap(2),
|
||||
Text(l10n.networkFooterBody, style: TextStyle(fontSize: 13, color: cs.mutedForeground)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)),
|
||||
const Gap(12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
@@ -710,3 +732,33 @@ class _GroupLabel extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Side by side when there is room, stacked when there is not.
|
||||
///
|
||||
/// Not a `Flex` with a flipped axis: the wide arrangement needs the leading
|
||||
/// child to take the slack, and the only way to express that is a flexed
|
||||
/// child — which is exactly what a vertical Flex inside a scroll view cannot
|
||||
/// have.
|
||||
class _RowOrColumn extends StatelessWidget {
|
||||
const _RowOrColumn({required this.narrow, required this.leading, required this.trailing});
|
||||
|
||||
final bool narrow;
|
||||
final Widget leading;
|
||||
final Widget trailing;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (narrow) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [leading, const Gap(12), trailing],
|
||||
);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [Expanded(child: leading), const Gap(12), trailing],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,18 @@ class WatchProgress {
|
||||
final bool connected;
|
||||
final Duration remaining;
|
||||
|
||||
/// How long the watch runs in total. Carried here so the UI can show
|
||||
/// progress without knowing the probe's window — the two would drift the
|
||||
/// moment either changed.
|
||||
final Duration window;
|
||||
|
||||
const WatchProgress({
|
||||
required this.browsed,
|
||||
required this.resolved,
|
||||
required this.addressAsks,
|
||||
required this.connected,
|
||||
required this.remaining,
|
||||
this.window = const Duration(seconds: 60),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ Future<NetworkCheck> guidedWatchCheck(
|
||||
addressAsks: addressAsks,
|
||||
connected: connected,
|
||||
remaining: remaining.isNegative ? Duration.zero : remaining,
|
||||
window: window,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
240
lib/widgets/network_test/network_live_test_card.dart
Normal file
240
lib/widgets/network_test/network_live_test_card.dart
Normal file
@@ -0,0 +1,240 @@
|
||||
import 'package:bike_control/gen/l10n.dart';
|
||||
import 'package:bike_control/services/network_self_test/network_probe_context.dart';
|
||||
import 'package:bike_control/widgets/network_test/network_tokens.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
|
||||
/// The live test: the one check that asks the rider to do something, and the
|
||||
/// only one that proves the whole path end to end.
|
||||
///
|
||||
/// It gets its own card rather than a row because it is the only check with a
|
||||
/// duration — everything else has already resolved by the time it is read.
|
||||
/// The head carries the ask and the countdown, the stepper shows how far the
|
||||
/// trainer app has got, and the tinting sets it apart from the settled checks
|
||||
/// above it.
|
||||
class NetworkLiveTestCard extends StatelessWidget {
|
||||
const NetworkLiveTestCard({super.key, required this.watch, this.appName, this.onSkip});
|
||||
|
||||
final WatchProgress watch;
|
||||
|
||||
/// The trainer app being waited on, so the first step can name it.
|
||||
final String? appName;
|
||||
|
||||
final VoidCallback? onSkip;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final tokens = NetworkTokens.of(context);
|
||||
final app = appName ?? '';
|
||||
|
||||
final elapsed = watch.window - watch.remaining;
|
||||
final progress = watch.window.inMilliseconds == 0
|
||||
? 0.0
|
||||
: (elapsed.inMilliseconds / watch.window.inMilliseconds).clamp(0.0, 1.0);
|
||||
|
||||
// The four things the trainer app does, in the order it does them. The
|
||||
// rider is watching their own app move through this list.
|
||||
final steps = <(String, bool)>[
|
||||
(l10n.networkWatchFoundUs(app), watch.browsed),
|
||||
(l10n.networkWatchResolved, watch.resolved),
|
||||
(l10n.networkWatchAddressAsks(watch.addressAsks), watch.addressAsks > 0),
|
||||
(l10n.networkWatchConnected, watch.connected),
|
||||
];
|
||||
// The first step not yet done is the one in progress; everything after it
|
||||
// is still ahead.
|
||||
final current = steps.indexWhere((s) => !s.$2);
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: cs.card,
|
||||
border: Border.all(color: cs.primary.withValues(alpha: 0.25)),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_head(context, l10n, cs, app),
|
||||
_bar(context, cs, progress),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(18, 14, 18, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (var i = 0; i < steps.length; i++)
|
||||
_Step(
|
||||
label: steps[i].$1,
|
||||
done: steps[i].$2,
|
||||
current: i == current,
|
||||
last: i == steps.length - 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_foot(context, l10n, cs, tokens),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _head(BuildContext context, AppLocalizations l10n, ColorScheme cs, String app) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 18),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.primary.withValues(alpha: 0.07),
|
||||
border: Border(bottom: BorderSide(color: cs.primary.withValues(alpha: 0.2))),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 22,
|
||||
height: 22,
|
||||
child: CircularProgressIndicator(size: 22, strokeWidth: 2, color: cs.primary),
|
||||
),
|
||||
const Gap(14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(l10n.networkWatchTitle, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w700)),
|
||||
Text(
|
||||
l10n.networkWatchPrompt(app),
|
||||
style: TextStyle(fontSize: 12, color: cs.mutedForeground),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Gap(12),
|
||||
Text(
|
||||
_clock(watch.remaining),
|
||||
style: Theme.of(context).typography.mono.copyWith(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: cs.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _bar(BuildContext context, ColorScheme cs, double progress) {
|
||||
return SizedBox(
|
||||
height: 3,
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(color: cs.primary.withValues(alpha: 0.2)),
|
||||
FractionallySizedBox(
|
||||
widthFactor: progress,
|
||||
child: Container(color: cs.primary),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _foot(BuildContext context, AppLocalizations l10n, ColorScheme cs, NetworkTokens tokens) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 13, horizontal: 18),
|
||||
decoration: BoxDecoration(
|
||||
color: tokens.pageBg,
|
||||
border: Border(top: BorderSide(color: tokens.hairline)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.networkWatchEndsItself,
|
||||
style: TextStyle(fontSize: 12, color: cs.mutedForeground),
|
||||
),
|
||||
),
|
||||
const Gap(12),
|
||||
Button.ghost(
|
||||
style: ButtonStyle.ghost(size: ButtonSize.small),
|
||||
onPressed: onSkip,
|
||||
child: Text(l10n.networkWatchSkip),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static String _clock(Duration d) {
|
||||
final seconds = d.inSeconds.clamp(0, 59 * 60);
|
||||
return '${seconds ~/ 60}:${(seconds % 60).toString().padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
|
||||
/// One line of the stepper: a bullet, the step, and the connector down to the
|
||||
/// next one. The connector turns green behind a step that has happened, so the
|
||||
/// card reads as a path being walked rather than a checklist.
|
||||
class _Step extends StatelessWidget {
|
||||
const _Step({required this.label, required this.done, required this.current, required this.last});
|
||||
|
||||
final String label;
|
||||
final bool done;
|
||||
final bool current;
|
||||
final bool last;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final tokens = NetworkTokens.of(context);
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 18,
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 26,
|
||||
child: Center(
|
||||
child: done
|
||||
? Icon(LucideIcons.check, size: 14, color: tokens.ok)
|
||||
: Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: current ? cs.primary : cs.border,
|
||||
boxShadow: current
|
||||
? [BoxShadow(color: cs.primary.withValues(alpha: 0.18), spreadRadius: 4)]
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!last)
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 1.5,
|
||||
color: done ? tokens.ok.withValues(alpha: 0.35) : tokens.hairline,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Gap(12),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 7, bottom: 7),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: current ? FontWeight.w600 : FontWeight.w500,
|
||||
color: done || current ? cs.foreground : cs.mutedForeground,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
120
test/widgets/network_troubleshooting_layout_test.dart
Normal file
120
test/widgets/network_troubleshooting_layout_test.dart
Normal file
@@ -0,0 +1,120 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:bike_control/bluetooth/devices/openbikecontrol/obp_mdns_backend.dart';
|
||||
import 'package:bike_control/pages/network_troubleshooting_page.dart';
|
||||
import 'package:bike_control/gen/l10n.dart';
|
||||
import 'package:bike_control/main.dart' show OtherLocalizationsDelegate;
|
||||
import 'package:bike_control/services/network_self_test/network_check.dart';
|
||||
import 'package:bike_control/services/network_self_test/network_fixes.dart';
|
||||
import 'package:bike_control/services/network_self_test/network_probe_context.dart';
|
||||
import 'package:bike_control/services/network_self_test/network_self_test_engine.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:bike_control/widgets/network_test/network_live_test_card.dart';
|
||||
|
||||
import '../widget_snapshot.dart';
|
||||
|
||||
NetworkProbeContext _ctx() => NetworkProbeContext(
|
||||
snapshot: null, snapshotError: null, emulatorStarted: true, trainerAppConnected: false,
|
||||
trainerAppConnectedNow: () => false, trainerAppName: 'MyWhoosh', backend: ObpMdnsBackend.platformDefault,
|
||||
advertisedHostname: null, platform: 'macos', resolve: (h) async => const [], tcpProbe: (a, p) async {},
|
||||
runProcess: (e, a) async => ProcessResult(0, 0, '', ''), queryLog: () => const [], sleep: (d) async {},
|
||||
now: () => DateTime(2026, 8, 22), onWatchProgress: (p) {},
|
||||
);
|
||||
|
||||
ProbeSpec _s(NetworkCheckId id, NetworkVerdict v, {List<NetworkFixId> fixes = const [], Map<String, String> detail = const {}}) =>
|
||||
ProbeSpec(id: id, timeout: const Duration(seconds: 5), run: (c) async => NetworkCheck(id: id, verdict: v, fixes: fixes, detail: detail));
|
||||
|
||||
Future<void> main() async {
|
||||
await ensureSnapshotHarness();
|
||||
|
||||
for (final (size, scale) in [
|
||||
(const Size(390, 844), 1.0),
|
||||
(const Size(360, 780), 1.0),
|
||||
(const Size(320, 700), 1.0),
|
||||
(const Size(390, 844), 1.3),
|
||||
(const Size(360, 780), 1.6),
|
||||
]) {
|
||||
testWidgets('overflow sweep ${size.width.toInt()} @${scale}x', (tester) async {
|
||||
final errors = <String>[];
|
||||
final previous = FlutterError.onError;
|
||||
FlutterError.onError = (details) => errors.add(details.exceptionAsString());
|
||||
addTearDown(() => FlutterError.onError = previous);
|
||||
|
||||
await tester.binding.setSurfaceSize(size);
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
|
||||
await tester.pumpWidget(MediaQuery(
|
||||
data: MediaQueryData(size: size, textScaler: TextScaler.linear(scale)),
|
||||
child: ShadcnApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: [
|
||||
...ShadcnLocalizations.localizationsDelegates,
|
||||
const OtherLocalizationsDelegate(),
|
||||
AppLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.delegate.supportedLocales,
|
||||
home: NetworkTroubleshootingPage(
|
||||
engineFactory: () => NetworkSelfTestEngine(contextBuilder: _ctx, probes: [
|
||||
_s(NetworkCheckId.methodListening, NetworkVerdict.pass, detail: const {'port': '36867'}),
|
||||
_s(NetworkCheckId.localNetworkPermission, NetworkVerdict.fail,
|
||||
fixes: [NetworkFixId.openLocalNetworkSettings], detail: const {'state': 'denied'}),
|
||||
_s(NetworkCheckId.resolveOwnHostname, NetworkVerdict.fail,
|
||||
fixes: [NetworkFixId.useOsResponderForObc, NetworkFixId.useResponderForObc],
|
||||
detail: const {'hostname': 'bikecontrol-3f2a.local'}),
|
||||
_s(NetworkCheckId.advertisedAddress, NetworkVerdict.pass, detail: const {'address': '192.168.178.197'}),
|
||||
]),
|
||||
),
|
||||
)));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(
|
||||
errors,
|
||||
isEmpty,
|
||||
reason: 'the page must lay out at ${size.width.toInt()}px @${scale}x without layout errors',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
for (final (size, scale) in [(const Size(360, 780), 1.0), (const Size(390, 844), 1.6)]) {
|
||||
testWidgets('live test card lays out at ${size.width.toInt()} @${scale}x', (tester) async {
|
||||
final errors = <String>[];
|
||||
final previous = FlutterError.onError;
|
||||
FlutterError.onError = (details) => errors.add(details.exceptionAsString());
|
||||
addTearDown(() => FlutterError.onError = previous);
|
||||
|
||||
await tester.binding.setSurfaceSize(size);
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
|
||||
await tester.pumpWidget(MediaQuery(
|
||||
data: MediaQueryData(size: size, textScaler: TextScaler.linear(scale)),
|
||||
child: ShadcnApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: [
|
||||
...ShadcnLocalizations.localizationsDelegates,
|
||||
const OtherLocalizationsDelegate(),
|
||||
AppLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: AppLocalizations.delegate.supportedLocales,
|
||||
home: const Scaffold(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: NetworkLiveTestCard(
|
||||
appName: 'MyWhoosh',
|
||||
watch: WatchProgress(
|
||||
browsed: true, resolved: true, addressAsks: 0, connected: false,
|
||||
remaining: Duration(seconds: 48), window: Duration(seconds: 60),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
// The spinner never stops; settle would hang.
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
|
||||
expect(errors, isEmpty, reason: 'the live test card must lay out at phone width');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user