Improve (and fix) the account expense indicator

This commit is contained in:
PapaTutuWawa 2025-05-06 22:18:33 +02:00
parent 63b5354b72
commit fc81ab38a0
3 changed files with 12 additions and 67 deletions

View File

@ -114,15 +114,7 @@ class AccountListPageState extends State<AccountListPage> {
), ),
Wrap( Wrap(
children: [ children: [
Padding( Padding(padding: EdgeInsets.all(8), child: BreakdownCard()),
padding: EdgeInsets.all(8),
//child: BreakdownCard(),
child: PieChartCard(
titleText: "Spending Breakdown",
fallbackText: "No spending available",
items: [],
),
),
], ],
), ),
], ],

View File

@ -127,7 +127,9 @@ class BreakdownCard extends StatelessWidget {
if (sectionData.isEmpty) { if (sectionData.isEmpty) {
return _buildCenterText("No expenses available"); return _buildCenterText("No expenses available");
} }
return OkanePieChart( return _buildCard(
OkanePieChart(
valueConverter: formatCurrency,
items: items:
data.expenses.entries data.expenses.entries
.map( .map(
@ -138,62 +140,12 @@ class BreakdownCard extends StatelessWidget {
), ),
) )
.toList(), .toList(),
),
"Available money: ${formatCurrency(data.usable)}",
); );
}, },
); );
}, },
); );
return ResponsiveCard(
titleText: "Expense Breakdown",
child: BlocBuilder<CoreCubit, CoreState>(
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(
items:
data.expenses.entries
.map(
(e) => (
title: e.key,
value: e.value,
color: colorHash(e.key),
),
)
.toList(),
);
},
);
},
),
);
} }
} }

View File

@ -34,7 +34,8 @@ class ResponsiveCard extends StatelessWidget {
child, child,
if (subtitleText != null) Text(subtitleText!), if (subtitleText != null)
Padding(padding: EdgeInsets.all(8), child: Text(subtitleText!)),
], ],
), ),
); );