From 1ce1342644a20e5a4436669c4851dcfe647b0054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Fri, 29 Dec 2023 19:43:27 +0100 Subject: [PATCH] feat(graphs): work on category pie chart --- lib/util/graphs.dart | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/util/graphs.dart b/lib/util/graphs.dart index 5a21330..a601667 100644 --- a/lib/util/graphs.dart +++ b/lib/util/graphs.dart @@ -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 entries; + final List categories; + + @override + Widget build(BuildContext context) => PieChart( + PieChartData( + sections: List.generate( + categories.length, + (index) => PieChartSectionData( + value: entries + .where( + (element) => element.category.id == categories[index].id) + .fold( + 0, + (previousValue, element) => + previousValue + element.data.amount, + ), + ), + ), + ), + ); +}