flutter-expense-tracker/lib/models/tracked_item.dart

56 lines
1.1 KiB
Dart

// Local
import '/models/item_type.dart';
import '/models/frequency.dart';
abstract class TrackedItem {
int? id;
ItemType? type;
String name;
double amount;
Frequency? frequency;
String description;
TrackedItem({
this.id,
this.type,
required this.name,
required this.amount,
this.frequency,
required this.description,
});
static String amountText = "Amount";
String getAmountText() => amountText;
@override
String toString() {
return toMap().toString();
}
double calcComparableAmountYearly() {
return frequency == null ? 0 : amount * frequency!.timesPerYear;
}
double calcComparableAmountDaily() {
return frequency == null ? 0 : amount / frequency!.numDays;
}
Map<String, dynamic> toMap() {
return frequency == null
? {
'id': id,
'name': name,
'amount': amount,
'description': description,
}
: {
'id': id,
'name': name,
'amount': amount,
'frequency': frequency!.title,
'description': description,
};
}
}