From d513f4147dbc69b9412920073484df030d5bc10f Mon Sep 17 00:00:00 2001 From: Jonas Acker Date: Mon, 28 Sep 2026 10:01:01 +0200 Subject: [PATCH] fix(theme): phone text at 1.1x, controls and icons stay at 1.25x With every text size now on the theme's type scale, shadcn's 1.25x mobile scaling made phone text wrap far more than on desktop. The app now passes its own phone scaling to ShadcnApp (main app and overlay): text 1.1x, while sizes, radii and icons keep 1.25x so icon buttons stay at ~45 px and BkTouchTarget's 48 dp targets are unaffected. The 11 px caption floor still holds in rendered size (12.1 px on phones). Co-Authored-By: Claude Opus 5.5 (1M context) --- lib/main.dart | 1 + lib/widgets/overlay/overlay_app.dart | 1 + lib/widgets/ui/app_theme.dart | 34 +++++++++++++++++++--- test/widget_snapshot.dart | 1 + test/widgets/overlay/overlay_app_test.dart | 2 +- test/widgets/ui/app_theme_test.dart | 28 +++++++++++++----- test/widgets/ui/bk_icon_button_test.dart | 18 +++++++++--- 7 files changed, 68 insertions(+), 17 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index ae5bb902..1ecab91a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -765,6 +765,7 @@ class _BikeControlAppState extends State { ], supportedLocales: AppLocalizations.delegate.supportedLocales, title: 'BikeControl', + scaling: BkTheme.scaling, darkTheme: BkTheme.build(Brightness.dark), locale: demoLocaleOverride.isNotEmpty ? Locale(demoLocaleOverride) diff --git a/lib/widgets/overlay/overlay_app.dart b/lib/widgets/overlay/overlay_app.dart index 451eabad..36ac7286 100644 --- a/lib/widgets/overlay/overlay_app.dart +++ b/lib/widgets/overlay/overlay_app.dart @@ -18,6 +18,7 @@ class OverlayShadcnApp extends StatelessWidget { Widget build(BuildContext context) { return ShadcnApp( debugShowCheckedModeBanner: false, + scaling: BkTheme.scaling, theme: BkTheme.build(Brightness.light), darkTheme: BkTheme.build(Brightness.dark), localizationsDelegates: [ diff --git a/lib/widgets/ui/app_theme.dart b/lib/widgets/ui/app_theme.dart index 4648a874..be8d3719 100644 --- a/lib/widgets/ui/app_theme.dart +++ b/lib/widgets/ui/app_theme.dart @@ -1,4 +1,5 @@ import 'package:bike_control/widgets/ui/colors.dart'; +import 'package:flutter/foundation.dart' show defaultTargetPlatform; import 'package:shadcn_flutter/shadcn_flutter.dart'; /// The one place BikeControl's shadcn themes are built. @@ -81,15 +82,40 @@ abstract final class BkTheme { chart5: Color(0xFFE23670), ); + /// Phone/tablet scaling. shadcn's own `AdaptiveScaling.mobile` scales + /// everything 1.25x; sizes, radii and icons keep that (it is what brings + /// icon buttons to a ~45 px target), but text at 1.25x wrapped the dense + /// cards far more than on desktop, so text gets 1.1x. + static const AdaptiveScaling mobileScaling = _BkMobileScaling(); + + /// The scaling every BikeControl `ShadcnApp` passes: [mobileScaling] on + /// iOS/Android (where shadcn would pick its mobile default), none elsewhere. + static AdaptiveScaling scalingFor(TargetPlatform platform) => switch (platform) { + TargetPlatform.iOS || TargetPlatform.android => mobileScaling, + _ => AdaptiveScaling.desktop, + }; + + /// [scalingFor] the platform the app runs on. + static AdaptiveScaling get scaling => scalingFor(defaultTargetPlatform); + /// Builds the theme for [brightness]. /// - /// Deliberately unscaled: on phones and tablets `ShadcnApp` applies - /// `AdaptiveScaling.mobile` (1.25x sizes, radius and text) on top of this, - /// which is what brings icon buttons to a ~45 px target. The theme used to - /// shrink phone text to 0.9x underneath that; it no longer does. + /// Deliberately unscaled: every app shell passes [scaling] to `ShadcnApp`, + /// which applies it on top of this. static ThemeData build(Brightness brightness) => ThemeData( colorScheme: brightness == Brightness.dark ? darkColorScheme : lightColorScheme, typography: const Typography.geist(), radius: radius, ); } + +/// [BkTheme.mobileScaling]: shadcn scales icons with text; this keeps them at +/// the control scale so icon buttons don't shrink with the text. +class _BkMobileScaling extends AdaptiveScaling { + const _BkMobileScaling() : super.only(radiusScaling: 1.25, sizeScaling: 1.25, textScaling: 1.1); + + static const double _iconScaling = 1.25; + + @override + ThemeData scale(ThemeData theme) => super.scale(theme).copyWith(iconTheme: () => theme.iconTheme.scale(_iconScaling)); +} diff --git a/test/widget_snapshot.dart b/test/widget_snapshot.dart index f6b9c3ea..f2f6941e 100644 --- a/test/widget_snapshot.dart +++ b/test/widget_snapshot.dart @@ -186,6 +186,7 @@ Future> captureWidget( AppLocalizations.delegate, ], supportedLocales: AppLocalizations.delegate.supportedLocales, + scaling: BkTheme.scaling, theme: lightTheme, darkTheme: darkTheme, themeMode: brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light, diff --git a/test/widgets/overlay/overlay_app_test.dart b/test/widgets/overlay/overlay_app_test.dart index c500c91f..eabcdaf0 100644 --- a/test/widgets/overlay/overlay_app_test.dart +++ b/test/widgets/overlay/overlay_app_test.dart @@ -37,7 +37,7 @@ void main() { final theme = Theme.of(ctx); expect(theme.brightness, brightness); expect(theme.colorScheme.primary, BkTheme.build(brightness).colorScheme.primary); - expect(theme.radius, AdaptiveScaling.mobile.scale(BkTheme.build(brightness)).radius); + expect(theme.radius, BkTheme.mobileScaling.scale(BkTheme.build(brightness)).radius); expect(AppLocalizations.maybeOf(ctx), isNotNull); }); } diff --git a/test/widgets/ui/app_theme_test.dart b/test/widgets/ui/app_theme_test.dart index 2365ae44..a19ef091 100644 --- a/test/widgets/ui/app_theme_test.dart +++ b/test/widgets/ui/app_theme_test.dart @@ -1,5 +1,6 @@ import 'package:bike_control/widgets/ui/app_theme.dart'; import 'package:bike_control/widgets/ui/colors.dart'; +import 'package:bike_control/widgets/ui/type_scale.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:shadcn_flutter/shadcn_flutter.dart'; @@ -53,19 +54,30 @@ void main() { expect(dark.scaling, light.scaling); }); - testWidgets('on a phone, shadcn scales controls 1.25x and text is not shrunk', (tester) async { + testWidgets('on a phone, controls scale 1.25x and text 1.1x', (tester) async { late ThemeData applied; await tester.pumpWidget( ShadcnApp( + scaling: BkTheme.scaling, theme: BkTheme.build(Brightness.light), - home: Builder(builder: (context) { - applied = Theme.of(context); - return const SizedBox(); - }), + home: Builder( + builder: (context) { + applied = Theme.of(context); + return const SizedBox(); + }, + ), ), ); - // flutter_test reports Android: ShadcnApp's mobile scaling applies. - expect(applied.scaling, closeTo(1.25, 0.001)); - expect(applied.typography.base.fontSize, closeTo(const Typography.geist().base.fontSize! * 1.25, 0.001)); + // flutter_test reports Android: the phone scaling applies. + const geist = Typography.geist(); + expect(applied.scaling, closeTo(1.25, 0.001), reason: 'tap targets keep the mobile size'); + expect(applied.typography.base.fontSize, closeTo(geist.base.fontSize! * 1.1, 0.001)); + // The 11 px floor holds in rendered size. + expect(applied.typography.caption.fontSize, greaterThanOrEqualTo(11)); + }); + + test('desktop is unscaled', () { + expect(BkTheme.scalingFor(TargetPlatform.macOS), AdaptiveScaling.desktop); + expect(BkTheme.scalingFor(TargetPlatform.windows), AdaptiveScaling.desktop); }); } diff --git a/test/widgets/ui/bk_icon_button_test.dart b/test/widgets/ui/bk_icon_button_test.dart index 6f07de75..52d0b103 100644 --- a/test/widgets/ui/bk_icon_button_test.dart +++ b/test/widgets/ui/bk_icon_button_test.dart @@ -7,13 +7,20 @@ import 'package:shadcn_flutter/shadcn_flutter.dart'; void main() { Future pump(WidgetTester tester, Widget child) => tester.pumpWidget( - ShadcnApp(theme: BkTheme.build(Brightness.light), home: Center(child: child)), + ShadcnApp( + scaling: BkTheme.scaling, + theme: BkTheme.build(Brightness.light), + home: Center(child: child), + ), ); testWidgets('announces its label as a button and taps through', (tester) async { final handle = tester.ensureSemantics(); var taps = 0; - await pump(tester, BkIconButton.ghost(icon: const Icon(LucideIcons.arrowLeft), label: 'Back', onPressed: () => taps++)); + await pump( + tester, + BkIconButton.ghost(icon: const Icon(LucideIcons.arrowLeft), label: 'Back', onPressed: () => taps++), + ); expect( find.semantics.byLabel('Back'), @@ -26,7 +33,10 @@ void main() { testWidgets('a disabled button says so', (tester) async { final handle = tester.ensureSemantics(); - await pump(tester, const BkIconButton.primary(icon: Icon(LucideIcons.send), label: 'Send message', onPressed: null)); + await pump( + tester, + const BkIconButton.primary(icon: Icon(LucideIcons.send), label: 'Send message', onPressed: null), + ); expect( find.semantics.byLabel('Send message'), isSemantics(isButton: true, isEnabled: false, hasEnabledState: true, hasTapAction: false), @@ -38,7 +48,7 @@ void main() { final handle = tester.ensureSemantics(); await pump(tester, BkIconButton.ghost(icon: const Icon(LucideIcons.x), label: 'Close', onPressed: () {})); await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); - // flutter_test reports Android, so ShadcnApp's mobile scaling applies. + // flutter_test reports Android, so the app's phone scaling applies. await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); handle.dispose(); });