From bce0b4d49ecdc12e161a6efbd894fcbda3f4cc76 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Mon, 10 Aug 2026 08:26:24 +0200 Subject: [PATCH] fix(ui): SelectableCard fills tight cells so app-picker tiles are pixel-uniform Stack was StackFit.loose: in the onboarding grid's tight cells the visible button shrink-wrapped its caption (uneven heights) while the active ring was Positioned.fill (cell-sized). StackFit.passthrough hands the cell constraints to the button, and a new alignment param (default topLeft, unchanged for existing rows) centers grid-tile content. Test asserts every tile button renders at exactly one Size at both 3- and 5-column widths. Co-Authored-By: Claude Fable 5 --- lib/pages/button_edit.dart | 11 +++++- lib/pages/onboarding/steps/step_app.dart | 1 + test/onboarding_grid_uniformity_test.dart | 48 +++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/onboarding_grid_uniformity_test.dart diff --git a/lib/pages/button_edit.dart b/lib/pages/button_edit.dart index f6a3424f..ee373e8a 100644 --- a/lib/pages/button_edit.dart +++ b/lib/pages/button_edit.dart @@ -1492,6 +1492,7 @@ class SelectableCard extends StatelessWidget { final String? value; final VoidCallback? onPressed; final bool isProOnly; + final AlignmentGeometry alignment; const SelectableCard({ super.key, @@ -1503,6 +1504,7 @@ class SelectableCard extends StatelessWidget { this.value, required this.onPressed, this.isProOnly = false, + this.alignment = Alignment.topLeft, }); @override @@ -1512,7 +1514,14 @@ class SelectableCard extends StatelessWidget { // Button keeps a static neutral border at all times; the colored "active" // ring is drawn as an overlay so AnimatedOpacity can cross-fade it in/out // without shadcn's internal style swap snapping between two border colors. + // + // StackFit.passthrough hands the incoming constraints to the button + // unchanged: under a tight cell (the onboarding app grid) the visible card + // fills the cell exactly — matching the Positioned.fill active ring — + // instead of shrink-wrapping its caption into uneven tiles. In the + // existing loose-height contexts (settings rows) it behaves as before. return Stack( + fit: StackFit.passthrough, children: [ Button.outline( style: @@ -1539,7 +1548,7 @@ class SelectableCard extends StatelessWidget { onPressed?.call(); } }, - alignment: Alignment.topLeft, + alignment: alignment, child: Container( width: double.infinity, padding: const EdgeInsets.symmetric(vertical: 2.0), diff --git a/lib/pages/onboarding/steps/step_app.dart b/lib/pages/onboarding/steps/step_app.dart index 90daf369..0b27b0b9 100644 --- a/lib/pages/onboarding/steps/step_app.dart +++ b/lib/pages/onboarding/steps/step_app.dart @@ -23,6 +23,7 @@ Widget onboardingAppBody(BuildContext context, for (final app in apps) SelectableCard( isActive: selected?.name == app.name, + alignment: Alignment.center, title: Center( child: app.logoAsset != null ? Image.asset(app.logoAsset!, height: 36, fit: BoxFit.contain) diff --git a/test/onboarding_grid_uniformity_test.dart b/test/onboarding_grid_uniformity_test.dart new file mode 100644 index 00000000..01d5ba63 --- /dev/null +++ b/test/onboarding_grid_uniformity_test.dart @@ -0,0 +1,48 @@ +// The app-picker tiles must be pixel-identical in size: the visible card +// (SelectableCard's inner Button) has to fill its uniform GridView cell +// instead of shrink-wrapping its caption (1-line vs 2-line captions and the +// selected state previously produced uneven tiles). +import 'package:bike_control/pages/button_edit.dart' show SelectableCard; +import 'package:bike_control/pages/onboarding/steps/step_app.dart'; +import 'package:bike_control/utils/keymap/apps/supported_app.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shadcn_flutter/shadcn_flutter.dart'; + +import 'widget_snapshot.dart'; + +Future main() async { + await ensureSnapshotHarness(); + + Future expectUniformTiles(WidgetTester tester, {required double width}) async { + await captureWidget( + tester, + name: 'onboarding_step_app_uniform_$width', + width: width, + builder: (c) => onboardingAppBody( + c, + selected: SupportedApp.supportedApps.first, + onSelect: (_) {}, + ), + ); + + final cards = find.byType(SelectableCard); + expect(cards, findsWidgets); + final sizes = {}; + for (final card in cards.evaluate()) { + final button = find + .descendant(of: find.byWidget(card.widget), matching: find.byWidgetPredicate((w) => w is Button)) + .first; + sizes.add(tester.getSize(button)); + } + expect(sizes, hasLength(1), + reason: 'visible tile cards must all be the same size at width $width, got: $sizes'); + } + + testWidgets('app grid tiles are uniform (3 columns)', (tester) async { + await expectUniformTiles(tester, width: 380); + }); + + testWidgets('app grid tiles are uniform (5 columns)', (tester) async { + await expectUniformTiles(tester, width: 640); + }); +}