40 lines
886 B
Dart

// Local
import '/models/item_type.dart';
import '/models/tracked_item.dart';
import '/models/frequency.dart';
class Expense extends TrackedItem {
static String amountText = "Cost";
Expense({
super.id,
super.type = ItemType.expense,
required super.name,
required super.amount,
required super.frequency,
required super.description,
});
factory Expense.fromMap(Map<String, dynamic> json) => Expense(
id: json['id'],
name: json['name'],
amount: json['cost'],
frequency: Frequency.values
.where((freq) => freq.title == json['frequency'])
.first,
description: json['description'],
);
@override
Map<String, dynamic> toMap() {
return {
'id': id,
'name': name,
'cost': amount,
'frequency': frequency!.title,
'description': description,
};
}
}