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(
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()),
],
),
],

View File

@ -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<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(
return _buildCard(
OkanePieChart(
valueConverter: formatCurrency,
items:
data.expenses.entries
.map(
@ -189,11 +140,12 @@ class BreakdownCard extends StatelessWidget {
),
)
.toList(),
);
},
);
},
),
),
"Available money: ${formatCurrency(data.usable)}",
);
},
);
},
);
}
}

View File

@ -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!)),
],
),
);