This commit is contained in:
2026-03-22 18:00:44 +03:00
parent 3e4b4db50c
commit 2fe390b068
16 changed files with 3744 additions and 74 deletions
+12 -9
View File
@@ -3,37 +3,40 @@ import '../../shared/models/transaction.dart';
import '../dashboard/provider.dart';
final categoryExpenseProvider = Provider<Map<String, double>>((ref) {
final txs = ref.watch(transactionsProvider)
.where((t) => t.type == TransactionType.expense);
final txsAsync = ref.watch(transactionsProvider);
final txs = txsAsync.valueOrNull ?? [];
final filtered = txs.where((t) => t.type == TransactionType.expense);
final map = <String, double>{};
for (final t in txs) {
for (final t in filtered) {
map[t.category] = (map[t.category] ?? 0) + t.amount;
}
return map;
});
final categoryIncomeProvider = Provider<Map<String, double>>((ref) {
final txs = ref.watch(transactionsProvider)
.where((t) => t.type == TransactionType.income);
final txsAsync = ref.watch(transactionsProvider);
final txs = txsAsync.valueOrNull ?? [];
final filtered = txs.where((t) => t.type == TransactionType.income);
final map = <String, double>{};
for (final t in txs) {
for (final t in filtered) {
map[t.category] = (map[t.category] ?? 0) + t.amount;
}
return map;
});
final monthlyBreakdownProvider = Provider<List<MonthlyData>>((ref) {
final txs = ref.watch(transactionsProvider)
.where((t) => t.type == TransactionType.expense);
final txsAsync = ref.watch(transactionsProvider);
final txs = txsAsync.valueOrNull ?? [];
final filtered = txs.where((t) => t.type == TransactionType.expense);
final now = DateTime.now();
final months = <MonthlyData>[];
for (var i = 5; i >= 0; i--) {
final month = DateTime(now.year, now.month - i, 1);
final total = txs
final total = filtered
.where((t) => t.date.year == month.year && t.date.month == month.month)
.fold(0.0, (sum, t) => sum + t.amount);
months.add(MonthlyData(month: month, amount: total));