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 <noreply@anthropic.com>
This commit is contained in:
Jonas Bark
2026-08-10 08:26:24 +02:00
parent 016d929855
commit bce0b4d49e
3 changed files with 59 additions and 1 deletions

View File

@@ -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),

View File

@@ -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)

View File

@@ -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<void> main() async {
await ensureSnapshotHarness();
Future<void> 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 = <Size>{};
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);
});
}