feat(graphs): add pie chart and category colors #19
1 changed files with 29 additions and 0 deletions
|
@ -4,6 +4,8 @@ import 'package:fl_chart/fl_chart.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.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]
|
/// Monthly/Yearly expense/income [LineChart]
|
||||||
class ExpensesLineChart extends StatelessWidget {
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue