diff --git a/lib/pages/button_simulator.dart b/lib/pages/button_simulator.dart index bcbd6f54..28e3df0a 100644 --- a/lib/pages/button_simulator.dart +++ b/lib/pages/button_simulator.dart @@ -421,10 +421,10 @@ class _ButtonSimulatorState extends State { Container( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4), decoration: BoxDecoration( - border: Border.all(color: Colors.blue), + border: Border.all(color: Theme.of(context).colorScheme.primary), borderRadius: BorderRadius.circular(4), ), - child: Text('Press a key...', style: TextStyle(color: Colors.blue)).small, + child: Text('Press a key...', style: TextStyle(color: Theme.of(context).colorScheme.primary)).small, ) else if (hotkey != null) KeyWidget(label: hotkey.toUpperCase()) diff --git a/lib/pages/paywall.dart b/lib/pages/paywall.dart index b92d1ea9..95ba498a 100644 --- a/lib/pages/paywall.dart +++ b/lib/pages/paywall.dart @@ -1,3 +1,4 @@ +import 'package:bike_control/widgets/ui/bk_tappable.dart'; import 'dart:async'; import 'package:bike_control/gen/l10n.dart'; @@ -581,7 +582,7 @@ class _PaywallState extends State { return ClipRRect( borderRadius: BorderRadius.circular(24), child: Container( - color: const Color(0xFFF5F5F8), + color: Theme.of(context).colorScheme.muted, child: Stack( children: [ Positioned( @@ -590,7 +591,7 @@ class _PaywallState extends State { bottom: 0, width: proColumnWidth, child: Container( - color: const Color(0xFFE6E7F5), + color: Theme.of(context).colorScheme.primary.withValues(alpha: 0.12), ), ), Padding( @@ -642,7 +643,7 @@ class _PaywallState extends State { fontWeight: FontWeight.bold, fontSize: 14, letterSpacing: 0.8, - color: Color(0xFF55565C), + color: Theme.of(context).colorScheme.mutedForeground, ), ), ), @@ -675,7 +676,7 @@ class _PaywallState extends State { children: [ Icon( feature.icon, - color: const Color(0xFF94959A), + color: Theme.of(context).colorScheme.mutedForeground, size: compact ? 16 : 22, ), const SizedBox(width: 12), @@ -683,7 +684,7 @@ class _PaywallState extends State { child: Text( feature.label, style: TextStyle( - color: const Color(0xFF4D4E54), + color: Theme.of(context).colorScheme.foreground, fontWeight: FontWeight.normal, fontSize: compact ? 13.5 : 19, height: 1.2, @@ -724,7 +725,7 @@ class _PaywallState extends State { style: TextStyle( fontSize: compact ? 12 : 24, fontWeight: FontWeight.w500, - color: Colors.black, + color: Theme.of(context).colorScheme.foreground, ), ), ), @@ -734,19 +735,19 @@ class _PaywallState extends State { style: TextStyle( fontSize: compact ? 12 : 24, fontWeight: FontWeight.w500, - color: Colors.black, + color: Theme.of(context).colorScheme.foreground, ), ), _PaywallCheck() => Icon( Icons.check_rounded, size: compact ? 22 : 48, - color: Colors.black, + color: Theme.of(context).colorScheme.foreground, ), _PaywallDash() => Container( width: compact ? 20 : 40, height: 3, decoration: BoxDecoration( - color: Colors.black, + color: Theme.of(context).colorScheme.foreground, borderRadius: BorderRadius.circular(3), ), ), @@ -804,6 +805,7 @@ class _PaywallState extends State { String? badge, }) { final selected = _selectedPlan == plan; + final cs = Theme.of(context).colorScheme; return Stack( clipBehavior: Clip.none, @@ -811,16 +813,19 @@ class _PaywallState extends State { // stay the same height even though only yearly has a billing line. fit: StackFit.passthrough, children: [ - GestureDetector( - onTap: () => _selectPlan(plan), + BkTappable( + onPressed: () => _selectPlan(plan), + selected: selected, + inMutuallyExclusiveGroup: true, + borderRadius: BorderRadius.circular(16), child: AnimatedContainer( duration: const Duration(milliseconds: 180), padding: const EdgeInsets.fromLTRB(16, 20, 16, 18), decoration: BoxDecoration( - color: const Color(0xFFF1F2F7), + color: cs.card, borderRadius: BorderRadius.circular(16), border: Border.all( - color: selected ? const Color(0xFF5A6ED6) : const Color(0xFFC1C2C8), + color: selected ? cs.primary : bkStrongBorder(context), width: selected ? 2.6 : 2, ), ), @@ -840,10 +845,10 @@ class _PaywallState extends State { child: Text( title, maxLines: 1, - style: const TextStyle( + style: TextStyle( fontSize: 17, fontWeight: FontWeight.w600, - color: Color(0xFF07070A), + color: cs.foreground, ), ), ), @@ -859,10 +864,10 @@ class _PaywallState extends State { child: Text( price, maxLines: 1, - style: const TextStyle( + style: TextStyle( fontSize: 17, fontWeight: FontWeight.w600, - color: Color(0xFF111216), + color: cs.foreground, ), ), ), @@ -872,10 +877,10 @@ class _PaywallState extends State { billed, maxLines: 1, overflow: TextOverflow.ellipsis, - style: const TextStyle( + style: TextStyle( fontSize: 13, fontWeight: FontWeight.w500, - color: Color(0xFF7A7B85), + color: cs.mutedForeground, ), ), ], @@ -891,13 +896,13 @@ class _PaywallState extends State { child: Container( padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 4), decoration: BoxDecoration( - color: const Color(0xFF5A6ED6), + color: cs.primary, borderRadius: BorderRadius.circular(18), ), child: Text( badge, - style: const TextStyle( - color: Colors.white, + style: TextStyle( + color: cs.primaryForeground, fontWeight: FontWeight.w800, fontSize: 15, letterSpacing: 0.3, @@ -922,17 +927,21 @@ class _PaywallState extends State { Widget _buildFullVersionCard(BuildContext context) { final selected = _selectedPlan == _PaywallPlan.fullVersion; - return GestureDetector( - onTap: () => _selectPlan(_PaywallPlan.fullVersion), + final cs = Theme.of(context).colorScheme; + return BkTappable( + onPressed: () => _selectPlan(_PaywallPlan.fullVersion), + selected: selected, + inMutuallyExclusiveGroup: true, + borderRadius: BorderRadius.circular(12), child: AnimatedContainer( duration: const Duration(milliseconds: 180), padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), decoration: BoxDecoration( // The one-time Base plan sits quieter than the Pro cards above it. - color: Colors.white, + color: cs.card, borderRadius: BorderRadius.circular(12), border: Border.all( - color: selected ? const Color(0xFF5A6ED6) : const Color(0xFFDDDEE5), + color: selected ? cs.primary : cs.border, width: selected ? 2 : 1.5, ), ), @@ -949,8 +958,8 @@ class _PaywallState extends State { children: [ Text( AppLocalizations.of(context).fullVersion, - style: const TextStyle( - color: Color(0xFF07070A), + style: TextStyle( + color: cs.foreground, fontSize: 13, fontWeight: FontWeight.w500, ), @@ -959,9 +968,9 @@ class _PaywallState extends State { _pricing.fullVersionSubtitle, maxLines: 1, overflow: TextOverflow.ellipsis, - style: const TextStyle( + style: TextStyle( fontSize: 11.5, - color: Color(0xFF6C6D73), + color: cs.mutedForeground, ), ), const SizedBox(height: 3), @@ -970,10 +979,10 @@ class _PaywallState extends State { // where their purchase went. Say so before they buy. Text( AppLocalizations.of(context).paywall_baseStoreNote(_storeName(context)), - style: const TextStyle( + style: TextStyle( fontSize: 11, height: 1.25, - color: Color(0xFF6C6D73), + color: cs.mutedForeground, ), ), ], @@ -997,6 +1006,7 @@ class _PaywallState extends State { : compact ? 20.0 : 34.0; + final cs = Theme.of(context).colorScheme; return AnimatedContainer( duration: const Duration(milliseconds: 180), width: size, @@ -1004,15 +1014,15 @@ class _PaywallState extends State { margin: EdgeInsets.only(top: compact ? 2 : 8), decoration: BoxDecoration( shape: BoxShape.circle, - color: selected ? const Color(0xFF5A6ED6) : Colors.transparent, + color: selected ? cs.primary : Colors.transparent, border: Border.all( - color: selected ? const Color(0xFF5A6ED6) : const Color(0xFFB8B9C0), + color: selected ? cs.primary : bkStrongBorder(context), width: selected ? 2 : 1.6, ), boxShadow: selected ? [ BoxShadow( - color: const Color(0xFF5A6ED6).withAlpha(70), + color: cs.primary.withAlpha(70), blurRadius: 10, offset: const Offset(0, 3), ), @@ -1023,18 +1033,24 @@ class _PaywallState extends State { ? Icon( Icons.check, size: small ? 10 : (compact ? 13 : 18), - color: Colors.white, + color: cs.primaryForeground, ) : null, ); } Widget _buildPurchaseButton(BuildContext context) { - return GestureDetector( - onTap: _isPurchasing ? null : _onPurchasePressed, + // The gradient is the brand's purchase call-to-action, so it stays drawn + // by hand; BkTappable gives it button semantics, keyboard focus and the + // click cursor. While a purchase runs it is disabled — and looks it. + return BkTappable( + onPressed: _isPurchasing ? null : _onPurchasePressed, + label: AppLocalizations.of(context).purchase, + excludeChildSemantics: true, + borderRadius: BorderRadius.circular(22), child: AnimatedOpacity( duration: const Duration(milliseconds: 120), - opacity: _isPurchasing ? 0.85 : 1, + opacity: _isPurchasing ? 0.55 : 1, child: Container( height: 52, decoration: BoxDecoration( diff --git a/lib/pages/workout/workout_summary_dialog.dart b/lib/pages/workout/workout_summary_dialog.dart index 337d842e..04e13277 100644 --- a/lib/pages/workout/workout_summary_dialog.dart +++ b/lib/pages/workout/workout_summary_dialog.dart @@ -76,42 +76,36 @@ class _WorkoutSummaryDialog extends StatelessWidget { _tile( context: context, icon: LucideIcons.timer, - color: const Color(0xFF0EA5E9), label: l10n.miniWorkoutSummaryDuration, value: _fmtDuration(summary.activeDuration), ), _tile( context: context, icon: LucideIcons.route, - color: const Color(0xFF10B981), label: l10n.miniWorkoutSummaryDistance, value: summary.distanceKm.asDistance(context), ), _tile( context: context, icon: LucideIcons.zap, - color: const Color(0xFFF59E0B), label: l10n.miniWorkoutSummaryAvgPower, value: '${summary.avgPowerW} W', ), _tile( context: context, icon: LucideIcons.trendingUp, - color: const Color(0xFFD97706), label: l10n.miniWorkoutSummaryMaxPower, value: '${summary.maxPowerW} W', ), _tile( context: context, icon: LucideIcons.rotateCw, - color: const Color(0xFF8B5CF6), label: l10n.miniWorkoutSummaryAvgCadence, value: '${summary.avgCadenceRpm} rpm', ), _tile( context: context, icon: LucideIcons.gauge, - color: const Color(0xFF0EA5E9), label: l10n.miniWorkoutSummaryAvgSpeed, value: summary.avgSpeedKph.asSpeed(context), ), @@ -119,7 +113,6 @@ class _WorkoutSummaryDialog extends StatelessWidget { _tile( context: context, icon: LucideIcons.heart, - color: const Color(0xFFEF4444), label: l10n.miniWorkoutSummaryAvgHeartRate, value: '${summary.avgHeartRateBpm} bpm', ), @@ -127,7 +120,6 @@ class _WorkoutSummaryDialog extends StatelessWidget { _tile( context: context, icon: LucideIcons.heartPulse, - color: const Color(0xFFDC2626), label: l10n.miniWorkoutSummaryMaxHeartRate, value: '${summary.maxHeartRateBpm} bpm', ), @@ -150,7 +142,6 @@ class _WorkoutSummaryDialog extends StatelessWidget { Widget _tile({ required BuildContext context, required IconData icon, - required Color color, required String label, required String value, }) { @@ -169,7 +160,9 @@ class _WorkoutSummaryDialog extends StatelessWidget { Row( spacing: 6, children: [ - Icon(icon, size: 14, color: color), + // One accent for every metric: the per-metric rainbow didn't + // reach 3:1 on the tile in either theme. + Icon(icon, size: 14, color: cs.primary), Expanded( child: Text( label.toUpperCase(), diff --git a/lib/widgets/ui/bk_tappable.dart b/lib/widgets/ui/bk_tappable.dart new file mode 100644 index 00000000..e36e6250 --- /dev/null +++ b/lib/widgets/ui/bk_tappable.dart @@ -0,0 +1,76 @@ +import 'package:shadcn_flutter/shadcn_flutter.dart'; + +/// A custom-drawn tappable surface that behaves like a button everywhere a +/// `GestureDetector` doesn't: it is reported as a button to screen readers, +/// takes keyboard focus on desktop (Tab to it, Enter/Space to press it, with a +/// focus ring), and shows the click cursor. +/// +/// Use it for cards and pills whose look a stock `Button` variant can't give. +class BkTappable extends StatelessWidget { + const BkTappable({ + super.key, + required this.child, + required this.onPressed, + this.label, + this.selected, + this.expanded, + this.inMutuallyExclusiveGroup = false, + this.borderRadius, + this.focusNode, + this.excludeChildSemantics = false, + }); + + final Widget child; + + /// Null disables the surface, which is also reported to accessibility. + final VoidCallback? onPressed; + + /// Spoken label. When null the child's own text is read. + final String? label; + + /// For a choice among options (plan cards, radio-like tiles). + final bool? selected; + + /// For a disclosure toggle: whether the section it controls is open. + final bool? expanded; + + /// Set for radio-like groups where exactly one option is selected. + final bool inMutuallyExclusiveGroup; + + /// Shape of the focus ring; match the child's corners. + final BorderRadiusGeometry? borderRadius; + + final FocusNode? focusNode; + + /// Replace the child's semantics with [label] (for surfaces whose children + /// are decorative or would read as fragments). + final bool excludeChildSemantics; + + @override + Widget build(BuildContext context) { + return Semantics( + container: true, + button: true, + enabled: onPressed != null, + selected: selected, + expanded: expanded, + inMutuallyExclusiveGroup: inMutuallyExclusiveGroup ? true : null, + label: label, + excludeSemantics: excludeChildSemantics, + // With excludeSemantics the Clickable's own tap action and focus flag + // are dropped too, so they are re-declared here. + onTap: excludeChildSemantics ? onPressed : null, + focusable: excludeChildSemantics ? onPressed != null : null, + child: Clickable( + enabled: onPressed != null, + onPressed: onPressed, + focusNode: focusNode, + mouseCursor: WidgetStatePropertyAll(onPressed != null ? SystemMouseCursors.click : SystemMouseCursors.basic), + decoration: borderRadius == null + ? null + : WidgetStatePropertyAll(BoxDecoration(borderRadius: borderRadius)), + child: child, + ), + ); + } +} diff --git a/lib/widgets/ui/pro_badge.dart b/lib/widgets/ui/pro_badge.dart index 2d7a7964..2c7730d8 100644 --- a/lib/widgets/ui/pro_badge.dart +++ b/lib/widgets/ui/pro_badge.dart @@ -23,7 +23,8 @@ class ProBadge extends StatelessWidget { child: Text( 'PRO', style: TextStyle( - color: Colors.white, + // White on this orange is 2.8:1 — below even the large-text floor. + color: const Color(0xFF1C1917), fontSize: fontSize, fontWeight: FontWeight.bold, ), diff --git a/test/pages/workout/workout_summary_dialog_contrast_test.dart b/test/pages/workout/workout_summary_dialog_contrast_test.dart new file mode 100644 index 00000000..aea04478 --- /dev/null +++ b/test/pages/workout/workout_summary_dialog_contrast_test.dart @@ -0,0 +1,59 @@ +import 'dart:io'; + +import 'package:bike_control/gen/l10n.dart'; +import 'package:bike_control/main.dart' show OtherLocalizationsDelegate; +import 'package:bike_control/pages/workout/workout_summary_dialog.dart'; +import 'package:bike_control/services/workout/workout_summary.dart'; +import 'package:bike_control/widgets/ui/app_theme.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shadcn_flutter/shadcn_flutter.dart'; + +import '../../helpers/contrast.dart'; +import '../../widget_snapshot.dart'; + +Future main() async { + await ensureSnapshotHarness(); + + final summary = WorkoutSummary( + startedAt: DateTime(2026, 9, 1), + activeDuration: const Duration(minutes: 42), + avgPowerW: 210, + maxPowerW: 480, + avgCadenceRpm: 88, + avgSpeedKph: 31.2, + distanceKm: 21.8, + avgHeartRateBpm: 142, + maxHeartRateBpm: 171, + sampleCount: 2520, + ); + + for (final brightness in Brightness.values) { + testWidgets('$brightness: summary tiles are legible, icons included', (tester) async { + tester.view.physicalSize = const Size(600, 1000) * 2.0; + tester.view.devicePixelRatio = 2.0; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + final theme = BkTheme.build(brightness); + await tester.pumpWidget( + ShadcnApp( + localizationsDelegates: [ + ...ShadcnLocalizations.localizationsDelegates, + const OtherLocalizationsDelegate(), + AppLocalizations.delegate, + ], + supportedLocales: AppLocalizations.delegate.supportedLocales, + theme: theme, + home: Builder( + builder: (context) => Button.primary( + onPressed: () => showWorkoutSummaryDialog(context: context, summary: summary, fitFile: File('/tmp/x.fit')), + child: const Text('open'), + ), + ), + ), + ); + await tester.tap(find.text('open')); + await tester.pumpAndSettle(); + expectLegibleText(tester, find.byType(AlertDialog), pageBackground: theme.colorScheme.popover); + }); + } +} diff --git a/test/paywall_a11y_test.dart b/test/paywall_a11y_test.dart new file mode 100644 index 00000000..0be55433 --- /dev/null +++ b/test/paywall_a11y_test.dart @@ -0,0 +1,89 @@ +// The paywall in both themes and to assistive tech: text reads against what +// is painted behind it, plan cards are selectable buttons, and the purchase +// button is a real, focusable button. +import 'package:bike_control/gen/l10n.dart'; +import 'package:bike_control/main.dart' show OtherLocalizationsDelegate; +import 'package:bike_control/pages/paywall.dart'; +import 'package:bike_control/utils/iap/iap_manager.dart'; +import 'package:bike_control/widgets/ui/app_theme.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:shadcn_flutter/shadcn_flutter.dart'; + +import 'helpers/contrast.dart'; +import 'widget_snapshot.dart'; + +Future main() async { + await ensureSnapshotHarness(); + + Future pump(WidgetTester tester, Brightness brightness) async { + tester.view.physicalSize = const Size(390, 1400) * 3.0; + tester.view.devicePixelRatio = 3.0; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + IAPManager.instance.isPurchased.value = false; + addTearDown(() => IAPManager.instance.isPurchased.value = true); + final theme = BkTheme.build(brightness, compact: true); + await tester.pumpWidget( + ShadcnApp( + debugShowCheckedModeBanner: false, + localizationsDelegates: [ + ...ShadcnLocalizations.localizationsDelegates, + const OtherLocalizationsDelegate(), + AppLocalizations.delegate, + ], + supportedLocales: AppLocalizations.delegate.supportedLocales, + theme: theme, + darkTheme: theme, + themeMode: brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light, + home: const SingleChildScrollView(child: Paywall(defaultToFullVersion: false)), + ), + ); + await tester.pump(const Duration(milliseconds: 300)); + return theme; + } + + for (final brightness in Brightness.values) { + testWidgets('$brightness: all paywall text is legible', (tester) async { + final theme = await pump(tester, brightness); + expectLegibleText(tester, find.byType(Paywall), pageBackground: theme.colorScheme.background); + }); + } + + testWidgets('plan cards are buttons that report which one is selected', (tester) async { + await pump(tester, Brightness.light); + final handle = tester.ensureSemantics(); + final l10n = AppLocalizations.of(tester.element(find.byType(Paywall))); + + final yearly = find.semantics.byLabel(RegExp(l10n.paywall_yearly)); + final monthly = find.semantics.byLabel(RegExp(l10n.paywall_monthly)); + expect(yearly, findsOne); + expect(monthly, findsOne); + expect(yearly, containsSemantics(isButton: true, isSelected: true, hasTapAction: true)); + expect(monthly, containsSemantics(isButton: true, isSelected: false, hasTapAction: true)); + + await tester.tap(find.text(l10n.paywall_monthly)); + await tester.pump(const Duration(milliseconds: 300)); + expect(find.semantics.byLabel(RegExp(l10n.paywall_monthly)), containsSemantics(isSelected: true)); + expect(find.semantics.byLabel(RegExp(l10n.paywall_yearly)), containsSemantics(isSelected: false)); + handle.dispose(); + }); + + testWidgets('the purchase button is a focusable, labelled button', (tester) async { + await pump(tester, Brightness.light); + final handle = tester.ensureSemantics(); + final l10n = AppLocalizations.of(tester.element(find.byType(Paywall))); + expect( + find.semantics.byLabel(l10n.purchase), + containsSemantics(isButton: true, hasTapAction: true, isFocusable: true, isEnabled: true), + ); + handle.dispose(); + }); + + testWidgets('paywall meets the labelled tap-target guideline', (tester) async { + await pump(tester, Brightness.light); + final handle = tester.ensureSemantics(); + await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); + handle.dispose(); + }); +}