From b72e811339af4076b5884bcf8b257e069db2a201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Mon, 8 Jan 2024 21:53:51 +0100 Subject: [PATCH] fix: differentiate expense/income with color --- CHANGELOG.md | 1 + lib/views/home.dart | 43 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8977c..757b0a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Added pie chart for expense/income data per category - Added recurring entries - Fixed wrong default sorting +- Differentiate expense and income on home view # 1.0.0-alpha+2 - Fixed localization issues - Added graphs for expenses and income per month/year diff --git a/lib/views/home.dart b/lib/views/home.dart index 950c459..563821a 100644 --- a/lib/views/home.dart +++ b/lib/views/home.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'dart:math'; +import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -146,7 +147,8 @@ class _HomeViewState extends State { } logger.d( - "Created ${selectedWallet!.recurringEntries.length} recurring entries"); + "Created ${selectedWallet!.recurringEntries.length} recurring entries", + ); // save and reload WalletManager.saveWallet(selectedWallet!).then((value) { @@ -408,10 +410,41 @@ class _HomeViewState extends State { ), ), title: Text(element.data.name), - subtitle: Text( - NumberFormat.currency( - symbol: selectedWallet!.currency.symbol, - ).format(element.data.amount), + subtitle: RichText( + text: TextSpan( + children: [ + TextSpan( + text: NumberFormat.currency( + symbol: selectedWallet!.currency.symbol, + ).format(element.data.amount), + style: TextStyle( + color: (element.type == EntryType.income) + ? (MediaQuery.of(context) + .platformBrightness == + Brightness.dark) + ? Colors.green.shade300 + : Colors.green.harmonizeWith( + Theme.of(context) + .colorScheme + .primary, + ) + : (MediaQuery.of(context) + .platformBrightness == + Brightness.dark) + ? Colors.red.shade300 + : Colors.red.harmonizeWith( + Theme.of(context) + .colorScheme + .primary, + ), + ), + ), + TextSpan( + text: + " | ${DateFormat.MMMd(locale).format(element.date)}", + ), + ], + ), ), ), ),