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) <noreply@anthropic.com>
This commit is contained in:
Jonas Acker
2026-09-28 10:01:01 +02:00
parent 23c0950785
commit d513f4147d
7 changed files with 68 additions and 17 deletions

View File

@@ -765,6 +765,7 @@ class _BikeControlAppState extends State<BikeControlApp> {
],
supportedLocales: AppLocalizations.delegate.supportedLocales,
title: 'BikeControl',
scaling: BkTheme.scaling,
darkTheme: BkTheme.build(Brightness.dark),
locale: demoLocaleOverride.isNotEmpty
? Locale(demoLocaleOverride)

View File

@@ -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: [

View File

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

View File

@@ -186,6 +186,7 @@ Future<List<File>> captureWidget(
AppLocalizations.delegate,
],
supportedLocales: AppLocalizations.delegate.supportedLocales,
scaling: BkTheme.scaling,
theme: lightTheme,
darkTheme: darkTheme,
themeMode: brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light,

View File

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

View File

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

View File

@@ -7,13 +7,20 @@ import 'package:shadcn_flutter/shadcn_flutter.dart';
void main() {
Future<void> 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();
});