stacked bar graph, edit / remove transaction & budget page base
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/account/models/transaction_line.dart';
|
||||
import 'package:tunas/domains/charts/models/chart_item.dart';
|
||||
@@ -9,6 +12,29 @@ import 'package:tunas/repositories/account/models/transaction.dart';
|
||||
part 'chart_event.dart';
|
||||
part 'chart_state.dart';
|
||||
|
||||
final colors = [
|
||||
Colors.purple.shade300,
|
||||
Colors.purple.shade500,
|
||||
Colors.purple.shade700,
|
||||
Colors.purple.shade900,
|
||||
Colors.blue.shade300,
|
||||
Colors.blue.shade500,
|
||||
Colors.blue.shade700,
|
||||
Colors.blue.shade900,
|
||||
Colors.green.shade300,
|
||||
Colors.green.shade500,
|
||||
Colors.green.shade700,
|
||||
Colors.green.shade900,
|
||||
Colors.yellow.shade300,
|
||||
Colors.yellow.shade500,
|
||||
Colors.yellow.shade700,
|
||||
Colors.yellow.shade900,
|
||||
Colors.red.shade300,
|
||||
Colors.red.shade500,
|
||||
Colors.red.shade700,
|
||||
Colors.red.shade900,
|
||||
];
|
||||
|
||||
class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
final AccountRepository _accountRepository;
|
||||
|
||||
@@ -95,7 +121,9 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
List<ChartItem> scopedCategoriesPositiveTotals = [];
|
||||
List<ChartItem> scopedCategoriesNegativeTotals = [];
|
||||
Map<int, FlSpot> scopedMonthlyTotals = {};
|
||||
Map<String, Map<String, double>> scopedCategoriesMonthlyTotals = {};
|
||||
Map<int, Map<String, double>> scopedCategoriesMonthlyTotals = {};
|
||||
Map<String, Color> categoriesColors = {};
|
||||
int colorIndex = 0;
|
||||
|
||||
for(var transaction in state.transactions) {
|
||||
double subTotal = globalTotal + transaction.value;
|
||||
@@ -120,6 +148,11 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (categoriesColors[transaction.category] == null) {
|
||||
categoriesColors[transaction.category] = colors[colorIndex];
|
||||
colorIndex++;
|
||||
}
|
||||
|
||||
if (transaction.value >= 0) {
|
||||
ChartItem? chartItem = scopedCategoriesPositiveTotals.firstWhere(
|
||||
(item) => item.label == transaction.category,
|
||||
@@ -142,7 +175,16 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
}
|
||||
);
|
||||
chartItem.value += transaction.value;
|
||||
|
||||
Map<String, double>? a = scopedCategoriesMonthlyTotals[transaction.date.month];
|
||||
if (scopedCategoriesMonthlyTotals[transaction.date.month] == null) {
|
||||
a = {};
|
||||
}
|
||||
|
||||
a?[transaction.category] = transaction.value.abs() + (a[transaction.category] ?? 0);
|
||||
scopedCategoriesMonthlyTotals[transaction.date.month] = a!;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<ChartItem> scopedCategoriesPositiveTotalsPercents = [];
|
||||
@@ -202,6 +244,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
scopedSimplifiedCategoriesNegativeTotalsPercents: scopedSimplifiedCategoriesNegativeTotalsPercents,
|
||||
scopedMonthlyTotals: scopedMonthlyTotals.values.toList(),
|
||||
scopedCategoriesMonthlyTotals: scopedCategoriesMonthlyTotals,
|
||||
categoriesColors: categoriesColors,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user