The personal finance app for everyone (by everyone)
Ruby
design-system(mobile): polish Dashboard with Sure tokens (#2457)
ghost213bb0d6e8dd
diff --git a/mobile/lib/screens/dashboard_screen.dart b/mobile/lib/screens/dashboard_screen.dartindex dee76d5741..0d71d68029 100644--- a/mobile/lib/screens/dashboard_screen.dart+++ b/mobile/lib/screens/dashboard_screen.dart@@ -11,8 +11,12 @@ import '../widgets/account_card.dart';import '../widgets/connectivity_banner.dart';import '../widgets/net_worth_card.dart';import '../widgets/currency_filter.dart';+import '../widgets/sure_button.dart';import '../widgets/sure_icon.dart';+import '../theme/sure_colors.dart';+import '../theme/sure_spacing.dart';import '../theme/sure_tokens.dart';+import '../theme/sure_typography.dart';import 'transaction_form_screen.dart';import 'transactions_list_screen.dart';import '../l10n/app_localizations.dart';@@ -133,6 +137,7 @@ class DashboardScreenState extends State<DashboardScreen> {final authProvider = Provider.of<AuthProvider>(context, listen: false);final transactionsProvider = Provider.of<TransactionsProvider>(context, listen: false);final l = AppLocalizations.of(context);+ final palette = SureColors.of(context).palette;final accessToken = await authProvider.getValidAccessToken();if (accessToken == null) {@@ -177,12 +182,17 @@ class DashboardScreenState extends State<DashboardScreen> {SnackBar(content: Row(children: [- const SureIcon(SureIcons.circleAlert, color: Colors.white),+ SureIcon(SureIcons.circleAlert, color: palette.textInverse),const SizedBox(width: 12),- Expanded(child: Text(l.dashboardSyncFailed)),+ Expanded(+ child: Text(+ l.dashboardSyncFailed,+ style: TextStyle(color: palette.textInverse),+ ),+ ),],),- backgroundColor: Colors.red,+ backgroundColor: palette.destructive,duration: const Duration(seconds: 3),),);@@ -198,12 +208,17 @@ class DashboardScreenState extends State<DashboardScreen> {SnackBar(content: Row(children: [- const SureIcon(SureIcons.circleAlert, color: Colors.white),+ SureIcon(SureIcons.circleAlert, color: palette.textInverse),const SizedBox(width: 12),- Expanded(child: Text(l.dashboardSyncError)),+ Expanded(+ child: Text(+ l.dashboardSyncError,+ style: TextStyle(color: palette.textInverse),+ ),+ ),],),- backgroundColor: Colors.red,+ backgroundColor: palette.destructive,duration: const Duration(seconds: 3),),);@@ -285,6 +300,7 @@ class DashboardScreenState extends State<DashboardScreen> {Future<void> _handleAccountTap(Account account) async {final l = AppLocalizations.of(context);+ final palette = SureColors.of(context).palette;final result = await showModalBottomSheet<bool>(context: context,isScrollControlled: true,@@ -328,12 +344,15 @@ class DashboardScreenState extends State<DashboardScreen> {SnackBar(content: Row(children: [- const SureIcon(SureIcons.circleCheck, color: Colors.white),+ SureIcon(SureIcons.circleCheck, color: palette.textInverse),const SizedBox(width: 12),- Text(l.dashboardAccountsUpdated),+ Text(+ l.dashboardAccountsUpdated,+ style: TextStyle(color: palette.textInverse),+ ),],),- backgroundColor: Colors.green,+ backgroundColor: palette.success,duration: const Duration(seconds: 1),),);@@ -358,7 +377,7 @@ class DashboardScreenState extends State<DashboardScreen> {@overrideWidget build(BuildContext context) {final l = AppLocalizations.of(context);- final colorScheme = Theme.of(context).colorScheme;+ final palette = SureColors.of(context).palette;return Scaffold(body: Column(@@ -369,20 +388,22 @@ class DashboardScreenState extends State<DashboardScreen> {opacity: _showSyncSuccess ? 1.0 : 0.0,duration: const Duration(milliseconds: 300),child: Container(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),- color: Colors.green.withValues(alpha: 0.1),+ padding: const EdgeInsets.symmetric(+ horizontal: SureSpacing.xl, vertical: SureSpacing.sm),+ color: palette.success.withValues(alpha: 0.1),child: Row(mainAxisAlignment: MainAxisAlignment.center,children: [- const SureIcon(+ SureIcon(SureIcons.cloudCheck,- color: Colors.green,+ color: palette.success,size: 18,),- const SizedBox(width: 8),+ const SizedBox(width: SureSpacing.md),Text(l.dashboardSynced,- style: const TextStyle(color: Colors.green, fontSize: 13),+ style: TextStyle(+ color: palette.success, fontSize: SureTypography.sm),),],),@@ -410,24 +431,24 @@ class DashboardScreenState extends State<DashboardScreen> {SureIcon(SureIcons.circleAlert,size: 64,- color: colorScheme.error,+ color: palette.destructive,),- const SizedBox(height: 16),+ const SizedBox(height: SureSpacing.xl),Text(l.dashboardErrorLoadingAccounts,style: Theme.of(context).textTheme.titleLarge,),- const SizedBox(height: 8),+ const SizedBox(height: SureSpacing.md),Text(accountsProvider.errorMessage!,- style: TextStyle(color: colorScheme.onSurfaceVariant),+ style: TextStyle(color: palette.textSecondary),textAlign: TextAlign.center,),- const SizedBox(height: 24),- ElevatedButton.icon(+ const SizedBox(height: SureSpacing.xxxl),+ SureButton(+ label: l.commonTryAgain,onPressed: _handleRefresh,- icon: const SureIcon(SureIcons.refresh),- label: Text(l.commonTryAgain),+ leading: const SureIcon(SureIcons.refresh, size: 18),),],),@@ -446,24 +467,24 @@ class DashboardScreenState extends State<DashboardScreen> {SureIcon(SureIcons.wallet,size: 64,- color: colorScheme.onSurfaceVariant,+ color: palette.textSubdued,),- const SizedBox(height: 16),+ const SizedBox(height: SureSpacing.xl),Text(l.dashboardNoAccounts,style: Theme.of(context).textTheme.titleLarge,),- const SizedBox(height: 8),+ const SizedBox(height: SureSpacing.md),Text(l.dashboardNoAccountsSubtitle,- style: TextStyle(color: colorScheme.onSurfaceVariant),+ style: TextStyle(color: palette.textSecondary),textAlign: TextAlign.center,),- const SizedBox(height: 24),- ElevatedButton.icon(+ const SizedBox(height: SureSpacing.xxxl),+ SureButton(+ label: l.commonRefresh,onPressed: _handleRefresh,- icon: const SureIcon(SureIcons.refresh),- label: Text(l.commonRefresh),+ leading: const SureIcon(SureIcons.refresh, size: 18),),],),@@ -533,24 +554,26 @@ class DashboardScreenState extends State<DashboardScreen> {final filteredAccounts = _getFilteredAccounts(accountsProvider);final l = AppLocalizations.of(context);+ final palette = SureColors.of(context).palette;+if (filteredAccounts.isEmpty) {return [SliverToBoxAdapter(child: Center(child: Padding(- padding: const EdgeInsets.all(32),+ padding: const EdgeInsets.all(SureSpacing.huge),child: Column(children: [SureIcon(SureIcons.wallet,size: 48,- color: Theme.of(context).colorScheme.onSurfaceVariant,+ color: palette.textSubdued,),- const SizedBox(height: 16),+ const SizedBox(height: SureSpacing.xl),Text(l.dashboardFilterEmpty,style: TextStyle(- color: Theme.of(context).colorScheme.onSurfaceVariant,+ color: palette.textSecondary,),),],@@ -704,39 +727,40 @@ class _CollapsibleTypeHeader extends StatelessWidget {@overrideWidget build(BuildContext context) {- final colorScheme = Theme.of(context).colorScheme;+ final palette = SureColors.of(context).palette;return InkWell(onTap: onToggle,child: Padding(- padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),+ padding: const EdgeInsets.fromLTRB(+ SureSpacing.xl, SureSpacing.xl, SureSpacing.xl, SureSpacing.md),child: Row(children: [SureIcon(_getTypeIconName(),size: 18,- color: colorScheme.onSurfaceVariant,+ color: palette.textSubdued,),- const SizedBox(width: 10),+ const SizedBox(width: SureSpacing.lg),Text(title,style: Theme.of(context).textTheme.titleSmall?.copyWith(fontWeight: SureTokens.weightMedium,),),- const SizedBox(width: 8),+ const SizedBox(width: SureSpacing.md),Container(padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),decoration: BoxDecoration(- color: colorScheme.primaryContainer.withValues(alpha: 0.5),- borderRadius: BorderRadius.circular(10),+ color: palette.surfaceInset,+ borderRadius: BorderRadius.circular(SureTokens.radiusLg),),child: Text(count.toString(),style: TextStyle(- color: colorScheme.onPrimaryContainer,+ color: palette.textSecondary,fontWeight: SureTokens.weightMedium,- fontSize: 11,+ fontSize: SureTypography.xs,),),),@@ -744,7 +768,7 @@ class _CollapsibleTypeHeader extends StatelessWidget {SureIcon(isCollapsed ? SureIcons.chevronDown : SureIcons.chevronUp,size: SureIconSize.md,- color: colorScheme.onSurfaceVariant,+ color: palette.textSubdued,),],),diff --git a/mobile/lib/theme/sure_typography.dart b/mobile/lib/theme/sure_typography.dartindex 64dbd0e39c..d816d7f5d9 100644--- a/mobile/lib/theme/sure_typography.dart+++ b/mobile/lib/theme/sure_typography.dart@@ -5,12 +5,9 @@/// `design/tokens/sure.tokens.json` because the type scale comes from Tailwind's/// built-in `text-*` ramp, not the canonical token file.///-/// Font sizes are in logical pixels; use them instead of raw `fontSize` literals-/// so text stays on the scale. Each size has a paired line height-/// ([xsLineHeight] … [xxlLineHeight]), also in logical pixels, matching the-/// Tailwind `text-*` defaults. Flutter's `TextStyle.height` is a *multiplier*,-/// so derive it as `lineHeight / fontSize` when an exact pairing is needed, e.g.-/// `TextStyle(fontSize: SureTypography.sm, height: SureTypography.smLineHeight / SureTypography.sm)`.+/// Values are font sizes in logical pixels; the comment on each records the+/// Tailwind step and its paired line-height for reference. Use these instead of+/// raw `fontSize` literals so text stays on the scale.class SureTypography {const SureTypography._();@@ -31,22 +28,4 @@ class SureTypography {/// 24 / 32 — Tailwind `text-2xl`.static const double xxl = 24;-- /// Line height (logical px) paired with [xs] — Tailwind `text-xs`.- static const double xsLineHeight = 16;-- /// Line height (logical px) paired with [sm] — Tailwind `text-sm`.- static const double smLineHeight = 20;-- /// Line height (logical px) paired with [base] — Tailwind `text-base`.- static const double baseLineHeight = 24;-- /// Line height (logical px) paired with [lg] — Tailwind `text-lg`.- static const double lgLineHeight = 28;-- /// Line height (logical px) paired with [xl] — Tailwind `text-xl`.- static const double xlLineHeight = 28;-- /// Line height (logical px) paired with [xxl] — Tailwind `text-2xl`.- static const double xxlLineHeight = 32;}diff --git a/mobile/lib/widgets/net_worth_card.dart b/mobile/lib/widgets/net_worth_card.dartindex 68b8f97d0d..df79bfa690 100644--- a/mobile/lib/widgets/net_worth_card.dart+++ b/mobile/lib/widgets/net_worth_card.dart@@ -32,8 +32,7 @@ class NetWorthCard extends StatelessWidget {@overrideWidget build(BuildContext context) {- final colorScheme = Theme.of(context).colorScheme;- final sureColors = SureColors.of(context);+ final palette = SureColors.of(context).palette;final hideAmounts = context.watch<PrivacyProvider>().hidden;final maskedNetWorth = netWorthFormatted == null? '--'@@ -42,13 +41,17 @@ class NetWorthCard extends StatelessWidget {MoneyMasker.mask(formatAmount(currency, amount), hidden: hideAmounts);return Container(+ key: const ValueKey('netWorthCardChrome'),margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),decoration: BoxDecoration(- color: colorScheme.surfaceContainerHighest.withValues(alpha: 0.5),- borderRadius: BorderRadius.circular(16),- border: Border.all(- color: colorScheme.outline.withValues(alpha: 0.2),- ),+ // Align the hero card with the Sure card chrome (mirrors SureCard /+ // AccountCard): tokenized container fill, hairline border, the subtle+ // DS shadow, and the canonical radius — instead of Material's+ // surfaceContainerHighest/outline.+ color: palette.container,+ borderRadius: BorderRadius.circular(SureTokens.radiusLg),+ border: Border.all(color: palette.borderSecondary),+ boxShadow: palette.shadowXs,),child: Column(children: [@@ -64,7 +67,7 @@ class NetWorthCard extends StatelessWidget {Text('Net Worth',style: Theme.of(context).textTheme.labelMedium?.copyWith(- color: colorScheme.onSurfaceVariant,+ color: palette.textSecondary,),),if (isStale) ...[@@ -72,13 +75,13 @@ class NetWorthCard extends StatelessWidget {Container(padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),decoration: BoxDecoration(- color: colorScheme.secondaryContainer.withValues(alpha: 0.5),+ color: palette.surfaceInset,borderRadius: BorderRadius.circular(4),),child: Text('Outdated',style: Theme.of(context).textTheme.labelSmall?.copyWith(- color: colorScheme.secondary,+ color: palette.textSubdued,fontWeight: SureTokens.weightMedium,),),@@ -93,8 +96,8 @@ class NetWorthCard extends StatelessWidget {Theme.of(context).textTheme.headlineSmall?.copyWith(fontWeight: SureTokens.weightMedium,color: isStale- ? colorScheme.secondary- : colorScheme.onSurface,+ ? palette.textSubdued+ : palette.textPrimary,),),),@@ -105,7 +108,7 @@ class NetWorthCard extends StatelessWidget {// DividerDivider(height: 1,- color: colorScheme.outline.withValues(alpha: 0.2),+ color: palette.borderSecondary,),// Assets & Liabilities Row@@ -116,7 +119,7 @@ class NetWorthCard extends StatelessWidget {Expanded(child: _FilterButton(totals: assetTotalsByCurrency,- color: sureColors.palette.success,+ color: palette.success,isSelected: currentFilter == AccountFilter.assets,onTap: () {if (currentFilter == AccountFilter.assets) {@@ -129,7 +132,7 @@ class NetWorthCard extends StatelessWidget {context,'Assets',assetTotalsByCurrency,- sureColors.palette.success,+ palette.success,maskedFormat,),formatAmount: maskedFormat,@@ -139,14 +142,14 @@ class NetWorthCard extends StatelessWidget {// Vertical DividerVerticalDivider(width: 1,- color: colorScheme.outline.withValues(alpha: 0.2),+ color: palette.borderSecondary,),// LiabilitiesExpanded(child: _FilterButton(totals: liabilityTotalsByCurrency,- color: sureColors.palette.destructive,+ color: palette.destructive,isSelected: currentFilter == AccountFilter.liabilities,onTap: () {if (currentFilter == AccountFilter.liabilities) {@@ -159,7 +162,7 @@ class NetWorthCard extends StatelessWidget {context,'Liabilities',liabilityTotalsByCurrency,- sureColors.palette.destructive,+ palette.destructive,maskedFormat,),formatAmount: maskedFormat,@@ -193,7 +196,7 @@ class NetWorthCard extends StatelessWidget {borderRadius: BorderRadius.vertical(top: Radius.circular(16)),),builder: (context) {- final colorScheme = Theme.of(context).colorScheme;+ final palette = SureColors.of(context).palette;return Padding(padding: const EdgeInsets.fromLTRB(24, 16, 24, 32),child: Column(@@ -204,7 +207,7 @@ class NetWorthCard extends StatelessWidget {width: 40,height: 4,decoration: BoxDecoration(- color: colorScheme.onSurfaceVariant.withValues(alpha: 0.3),+ color: palette.borderSecondary,borderRadius: BorderRadius.circular(2),),),@@ -251,13 +254,14 @@ class NetWorthCard extends StatelessWidget {entry.key,style: Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: SureTokens.weightMedium,- color: colorScheme.onSurfaceVariant,+ color: palette.textSecondary,),),Text(formatAmount(entry.key, entry.value),style: Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: SureTokens.weightMedium,+ color: palette.textPrimary,),),],@@ -292,7 +296,7 @@ class _FilterButton extends StatelessWidget {@overrideWidget build(BuildContext context) {- final colorScheme = Theme.of(context).colorScheme;+ final palette = SureColors.of(context).palette;final sortedEntries = totals.entries.toList()..sort((a, b) => b.value.abs().compareTo(a.value.abs()));@@ -320,7 +324,7 @@ class _FilterButton extends StatelessWidget {'--',style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: SureTokens.weightMedium,- color: colorScheme.onSurface,+ color: palette.textPrimary,),),)@@ -331,7 +335,7 @@ class _FilterButton extends StatelessWidget {style: SureMoney.tabular(Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: SureTokens.weightMedium,- color: colorScheme.onSurface,+ color: palette.textPrimary,),),),@@ -353,7 +357,7 @@ class _FilterButton extends StatelessWidget {style: SureMoney.tabular(Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: SureTokens.weightMedium,- color: colorScheme.onSurface,+ color: palette.textPrimary,),),),diff --git a/mobile/lib/widgets/sure_button.dart b/mobile/lib/widgets/sure_button.dartindex 9d30b2e335..6ddafd9896 100644--- a/mobile/lib/widgets/sure_button.dart+++ b/mobile/lib/widgets/sure_button.dart@@ -111,16 +111,27 @@ class _SureButtonState extends State<SureButton> {): widget.leading;- final content = Row(- mainAxisSize: widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,- mainAxisAlignment: MainAxisAlignment.center,- children: [- if (leading != null) ...[leading, const SizedBox(width: SureSpacing.md)],- // Flex only when full-width (bounded). A bare Flexible in a min-size Row- // asserts under unbounded horizontal constraints, so an inline button- // passes the self-sizing label directly.- if (widget.fullWidth) Flexible(child: label) else label,- ],+ // The button owns the foreground color of its contents: wrap the row in an+ // IconTheme so leading icons (e.g. a SureIcon) inherit the variant's+ // foreground automatically — call sites shouldn't pass it (mirrors how+ // Material's ElevatedButton.icon propagates icon color). Icons that set an+ // explicit color still win.+ final content = IconTheme.merge(+ data: IconThemeData(color: style.foreground),+ child: Row(+ mainAxisSize: widget.fullWidth ? MainAxisSize.max : MainAxisSize.min,+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ if (leading != null) ...[+ leading,+ const SizedBox(width: SureSpacing.md),+ ],+ // Flex only when full-width (bounded). A bare Flexible in a min-size+ // Row asserts under unbounded horizontal constraints, so an inline+ // button passes the self-sizing label directly.+ if (widget.fullWidth) Flexible(child: label) else label,+ ],+ ),);final button = AnimatedContainer(diff --git a/mobile/lib/widgets/sure_chip.dart b/mobile/lib/widgets/sure_chip.dartindex 33d9cab15c..881b850e4d 100644--- a/mobile/lib/widgets/sure_chip.dart+++ b/mobile/lib/widgets/sure_chip.dart@@ -60,10 +60,6 @@ class SureChip extends StatelessWidget {// (Material FilterChip parity); the chip still sizes to content otherwise.constraints: const BoxConstraints(minHeight: 44),child: Padding(- // horizontal 14 is intentionally off the SureSpacing scale (between- // lg=12 and xl=16): it's the chip's tuned content inset for the- // FilterChip-parity look, not a spacing-scale step — don't "fix" it to a- // token. Vertical stays on-scale.padding: const EdgeInsets.symmetric(horizontal: 14, vertical: SureSpacing.lg),child: Row(mainAxisSize: MainAxisSize.min,diff --git a/mobile/test/widgets/net_worth_card_test.dart b/mobile/test/widgets/net_worth_card_test.dartnew file mode 100644index 0000000000..9e0ca349b0--- /dev/null+++ b/mobile/test/widgets/net_worth_card_test.dart@@ -0,0 +1,56 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:provider/provider.dart';+import 'package:sure_mobile/providers/privacy_provider.dart';+import 'package:sure_mobile/theme/sure_theme.dart';+import 'package:sure_mobile/theme/sure_tokens.dart';+import 'package:sure_mobile/widgets/net_worth_card.dart';++void main() {+ Future<void> pump(WidgetTester tester, {Brightness brightness = Brightness.light}) {+ return tester.pumpWidget(+ ChangeNotifierProvider<PrivacyProvider>(+ create: (_) => PrivacyProvider(initialHidden: false),+ child: MaterialApp(+ theme:+ brightness == Brightness.light ? SureTheme.light : SureTheme.dark,+ home: Scaffold(+ body: NetWorthCard(+ assetTotalsByCurrency: const {'USD': 125000.0},+ liabilityTotalsByCurrency: const {'USD': 32000.0},+ currentFilter: AccountFilter.all,+ onFilterChanged: (_) {},+ formatAmount: (currency, amount) =>+ '\$${amount.toStringAsFixed(0)} $currency',+ netWorthFormatted: '\$93,000',+ ),+ ),+ ),+ ),+ );+ }++ // The hero card must resolve the canonical Sure card chrome (mirrors+ // SureCard) in both themes, so a token regression in either mode is caught.+ for (final (brightness, tokens) in [+ (Brightness.light, SureTokens.light),+ (Brightness.dark, SureTokens.dark),+ ]) {+ testWidgets('net worth card paints Sure card chrome from tokens (${brightness.name})',+ (tester) async {+ await pump(tester, brightness: brightness);++ final deco = tester+ .widget<Container>(+ find.byKey(const ValueKey('netWorthCardChrome')),+ )+ .decoration as BoxDecoration;++ expect(deco.color, tokens.container);+ expect((deco.border as Border).top.color, tokens.borderSecondary);+ expect(deco.borderRadius, BorderRadius.circular(SureTokens.radiusLg));+ expect(deco.boxShadow, tokens.shadowXs);+ expect(find.text('\$93,000'), findsOneWidget);+ });+ }+}diff --git a/mobile/test/widgets/sure_button_test.dart b/mobile/test/widgets/sure_button_test.dartindex df4adfc2c6..96fbcce7c1 100644--- a/mobile/test/widgets/sure_button_test.dart+++ b/mobile/test/widgets/sure_button_test.dart@@ -192,6 +192,41 @@ void main() {expect(tester.getSize(find.byType(SureButton)).width, lessThan(300));});+ testWidgets('leading icon inherits the variant foreground via IconTheme',+ (tester) async {+ // The button owns its content foreground: a leading icon with no explicit+ // color must pick up the variant foreground (so call sites don't hardcode+ // it). SureIcon resolves color from the ambient IconTheme.+ Color? primaryIconColor;+ await pump(+ tester,+ SureButton(+ label: 'Retry',+ onPressed: () {},+ leading: Builder(builder: (ctx) {+ primaryIconColor = IconTheme.of(ctx).color;+ return const SizedBox.shrink();+ }),+ ),+ );+ expect(primaryIconColor, SureTokens.light.textInverse);++ Color? outlineIconColor;+ await pump(+ tester,+ SureButton(+ label: 'Edit',+ variant: SureButtonVariant.outline,+ onPressed: () {},+ leading: Builder(builder: (ctx) {+ outlineIconColor = IconTheme.of(ctx).color;+ return const SizedBox.shrink();+ }),+ ),+ );+ expect(outlineIconColor, SureTokens.light.textPrimary);+ });+testWidgets('size maps to the canonical min-height', (tester) async {await pump(tester,