Abschnitt 5
This commit is contained in:
+27
-2
@@ -6,10 +6,10 @@ import 'package:intl/intl.dart';
|
||||
final formatter = DateFormat('dd.MM.yyyy');
|
||||
const uuid = Uuid();
|
||||
|
||||
enum Category { foot, travel, leisure, work }
|
||||
enum Category { food, travel, leisure, work }
|
||||
|
||||
const categoryIcons = {
|
||||
Category.foot: Icons.lunch_dining,
|
||||
Category.food: Icons.lunch_dining,
|
||||
Category.travel: Icons.flight_takeoff,
|
||||
Category.leisure: Icons.movie,
|
||||
Category.work: Icons.work,
|
||||
@@ -33,3 +33,28 @@ class Expense {
|
||||
return formatter.format(date);
|
||||
}
|
||||
}
|
||||
|
||||
class ExpenseBucket {
|
||||
const ExpenseBucket({
|
||||
required this.category,
|
||||
required this.expenses,
|
||||
});
|
||||
|
||||
ExpenseBucket.forCategory(List<Expense> allExpenses, this.category)
|
||||
: expenses = allExpenses
|
||||
.where((expense) => expense.category == category)
|
||||
.toList();
|
||||
|
||||
final Category category;
|
||||
final List<Expense> expenses;
|
||||
|
||||
double get totalExpenses {
|
||||
double sum = 0;
|
||||
|
||||
for (final expense in expenses) {
|
||||
sum += expense.amount;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user