From fc81ab38a04cae8718cfc02d2e575520776b404d Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Tue, 6 May 2025 22:18:33 +0200 Subject: [PATCH] Improve (and fix) the account expense indicator --- lib/ui/pages/account/account.dart | 10 +--- lib/ui/pages/account/breakdown_card.dart | 66 ++++-------------------- lib/ui/widgets/piechart_card.dart | 3 +- 3 files changed, 12 insertions(+), 67 deletions(-) diff --git a/lib/ui/pages/account/account.dart b/lib/ui/pages/account/account.dart index 6305366..9d1459f 100644 --- a/lib/ui/pages/account/account.dart +++ b/lib/ui/pages/account/account.dart @@ -114,15 +114,7 @@ class AccountListPageState extends State { ), Wrap( children: [ - Padding( - padding: EdgeInsets.all(8), - //child: BreakdownCard(), - child: PieChartCard( - titleText: "Spending Breakdown", - fallbackText: "No spending available", - items: [], - ), - ), + Padding(padding: EdgeInsets.all(8), child: BreakdownCard()), ], ), ], diff --git a/lib/ui/pages/account/breakdown_card.dart b/lib/ui/pages/account/breakdown_card.dart index 85e3dad..98f3ebf 100644 --- a/lib/ui/pages/account/breakdown_card.dart +++ b/lib/ui/pages/account/breakdown_card.dart @@ -127,58 +127,9 @@ class BreakdownCard extends StatelessWidget { if (sectionData.isEmpty) { return _buildCenterText("No expenses available"); } - return OkanePieChart( - items: - data.expenses.entries - .map( - (e) => ( - title: e.key, - value: e.value, - color: colorHash(e.key), - ), - ) - .toList(), - ); - }, - ); - }, - ); - return ResponsiveCard( - titleText: "Expense Breakdown", - child: BlocBuilder( - builder: (context, state) { - if (bloc.activeAccount == null) { - return Text("No active account"); - } - - return FutureBuilder( - future: getLastTransactions( - bloc.activeAccount!, - DateTime.now(), - 30, - ), - builder: (context, snapshot) { - if (!snapshot.hasData) { - return CircularProgressIndicator(); - } - - final data = _computeSections(snapshot.data!); - final sectionData = - data.expenses.entries - .map( - (entry) => PieChartSectionData( - value: entry.value, - title: formatCurrency(entry.value, precise: false), - titleStyle: TextStyle(fontWeight: FontWeight.bold), - radius: 40, - color: data.colors[entry.key]!, - ), - ) - .toList(); - if (sectionData.isEmpty) { - return Center(child: Text("No expenses")); - } - return OkanePieChart( + return _buildCard( + OkanePieChart( + valueConverter: formatCurrency, items: data.expenses.entries .map( @@ -189,11 +140,12 @@ class BreakdownCard extends StatelessWidget { ), ) .toList(), - ); - }, - ); - }, - ), + ), + "Available money: ${formatCurrency(data.usable)}", + ); + }, + ); + }, ); } } diff --git a/lib/ui/widgets/piechart_card.dart b/lib/ui/widgets/piechart_card.dart index a6cd5d6..f7afe72 100644 --- a/lib/ui/widgets/piechart_card.dart +++ b/lib/ui/widgets/piechart_card.dart @@ -34,7 +34,8 @@ class ResponsiveCard extends StatelessWidget { child, - if (subtitleText != null) Text(subtitleText!), + if (subtitleText != null) + Padding(padding: EdgeInsets.all(8), child: Text(subtitleText!)), ], ), );