feat(graphs): work on category pie chart

This commit is contained in:
Matyáš Caras 2023-12-29 19:43:27 +01:00
parent 3be02d3ffe
commit 1ce1342644
Signed by untrusted user who does not match committer: hernik
GPG key ID: 2A3175F98820C5C6

View file

@ -4,6 +4,8 @@ import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:prasule/api/category.dart';
import 'package:prasule/api/walletentry.dart';
/// Monthly/Yearly expense/income [LineChart]
class ExpensesLineChart extends StatelessWidget {
@ -295,3 +297,30 @@ class ExpensesBarChart extends StatelessWidget {
),
);
}
class CategoriesPieChart extends StatelessWidget {
const CategoriesPieChart(
{super.key, required this.entries, required this.categories});
final List<WalletSingleEntry> entries;
final List<WalletCategory> categories;
@override
Widget build(BuildContext context) => PieChart(
PieChartData(
sections: List<PieChartSectionData>.generate(
categories.length,
(index) => PieChartSectionData(
value: entries
.where(
(element) => element.category.id == categories[index].id)
.fold<double>(
0,
(previousValue, element) =>
previousValue + element.data.amount,
),
),
),
),
);
}