style: fix dark mode theme support by resolving colors from BuildContext

This commit is contained in:
alexis 2026-07-11 21:56:27 +02:00
parent 644da80c4e
commit a207302193
6 changed files with 32 additions and 23 deletions

View file

@ -39,9 +39,10 @@ class _YnabAppState extends ConsumerState<YnabApp> {
@override
Widget build(BuildContext context) {
final selectedIndex = ref.watch(_selectedIndexProvider);
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
return Scaffold(
backgroundColor: kSurfaceBg,
bottomNavigationBar: NavigationBar(
selectedIndex: selectedIndex,
onDestinationSelected: (int index) {
@ -62,29 +63,29 @@ class _YnabAppState extends ConsumerState<YnabApp> {
Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: kSurfaceBg,
color: colorScheme.surface,
border: Border(
bottom: BorderSide(color: kDivider, width: 0.5),
bottom: BorderSide(color: colorScheme.outlineVariant, width: 0.5),
),
),
child: Row(
children: [
Text(
_navItems[selectedIndex].label,
style: const TextStyle(
color: kTextPrimary,
style: TextStyle(
color: colorScheme.onSurface,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
const Spacer(),
IconButton(
icon: const Icon(Icons.add, color: kGreenAccent),
icon: Icon(Icons.add, color: colorScheme.primary),
onPressed: () {},
tooltip: 'Ajouter une transaction',
),
IconButton(
icon: const Icon(Icons.search, color: kTextSecondary),
icon: Icon(Icons.search, color: colorScheme.onSurfaceVariant),
onPressed: () {},
tooltip: 'Rechercher',
),

View file

@ -54,10 +54,10 @@ class _AccountCard extends StatelessWidget {
width: 44,
height: 44,
decoration: BoxDecoration(
color: kSurfaceElevated,
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(12),
),
child: Icon(_icon(), color: kTextSecondary, size: 22),
child: Icon(_icon(), color: Theme.of(context).colorScheme.onSurfaceVariant, size: 22),
),
const SizedBox(width: 14),
Expanded(
@ -78,7 +78,7 @@ class _AccountCard extends StatelessWidget {
formatCurrency(account.balance),
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w700,
color: account.balance >= 0 ? kGreenAccent : kRedAccent,
color: account.balance >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
],

View file

@ -62,7 +62,7 @@ class _CategoryGroupTile extends ConsumerWidget {
Icon(
expanded ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right,
size: 18,
color: kTextSecondary,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(width: 8),
Text(group.name,
@ -124,7 +124,7 @@ class _CategoryRow extends ConsumerWidget {
formatCurrency(remaining),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: remaining >= 0 ? kGreenAccent : kRedAccent,
color: remaining >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
],
@ -134,9 +134,9 @@ class _CategoryRow extends ConsumerWidget {
borderRadius: BorderRadius.circular(4),
child: LinearProgressIndicator(
value: pct,
backgroundColor: kDivider,
backgroundColor: Theme.of(context).colorScheme.outlineVariant,
valueColor: AlwaysStoppedAnimation<Color>(
remaining >= 0 ? kGreenAccent : kRedAccent,
remaining >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
minHeight: 4,
),

View file

@ -72,7 +72,7 @@ class _BalanceCard extends StatelessWidget {
style: Theme.of(context).textTheme.headlineLarge?.copyWith(
fontSize: 36,
fontWeight: FontWeight.w700,
color: balance >= 0 ? kGreenAccent : kRedAccent,
color: balance >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
],
@ -101,13 +101,13 @@ class _AccountMiniCard extends StatelessWidget {
margin: const EdgeInsets.only(bottom: 6),
child: ListTile(
dense: true,
leading: Icon(_icon(), color: kTextSecondary),
leading: Icon(_icon(), color: Theme.of(context).colorScheme.onSurfaceVariant),
title: Text(account.name, style: Theme.of(context).textTheme.bodyMedium),
trailing: Text(
formatCurrency(account.balance),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: account.balance >= 0 ? kGreenAccent : kRedAccent,
color: account.balance >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
),
@ -127,11 +127,11 @@ class _TxItem extends StatelessWidget {
dense: true,
leading: CircleAvatar(
radius: 18,
backgroundColor: kSurfaceElevated,
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Icon(
transaction.amount >= 0 ? Icons.arrow_downward : Icons.arrow_upward,
size: 16,
color: transaction.amount >= 0 ? kGreenAccent : kRedAccent,
color: transaction.amount >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
title: Text(transaction.payee, style: Theme.of(context).textTheme.bodyMedium),
@ -143,7 +143,7 @@ class _TxItem extends StatelessWidget {
formatCurrency(transaction.amount),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: transaction.amount >= 0 ? kGreenAccent : kRedAccent,
color: transaction.amount >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
),

View file

@ -22,11 +22,11 @@ class TransactionsScreen extends ConsumerWidget {
dense: true,
leading: CircleAvatar(
radius: 18,
backgroundColor: kSurfaceElevated,
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
child: Icon(
t.amount >= 0 ? Icons.arrow_downward : Icons.arrow_upward,
size: 16,
color: t.amount >= 0 ? kGreenAccent : kRedAccent,
color: t.amount >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
title: Text(t.payee, style: Theme.of(context).textTheme.bodyMedium),
@ -42,7 +42,7 @@ class TransactionsScreen extends ConsumerWidget {
formatCurrency(t.amount),
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
color: t.amount >= 0 ? kGreenAccent : kRedAccent,
color: t.amount >= 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
),
),
],

View file

@ -133,6 +133,14 @@ final ThemeData ynabDarkTheme = ThemeData(
seedColor: const Color(0xFFCAD8C3),
brightness: Brightness.dark,
),
cardTheme: CardThemeData(
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: const BorderSide(color: Color(0xFF43493E), width: 1),
),
clipBehavior: Clip.antiAlias,
),
);
// Utils