Move down to only 1 abstract data type with a nully Frequency. Should aid in making the Expense page usable for all 3 data type.

This commit is contained in:
2025-02-21 08:56:50 -07:00
parent 992195b9a0
commit be66f52cbf
11 changed files with 133 additions and 139 deletions
+49
View File
@@ -0,0 +1,49 @@
// Local
import '/models/frequency.dart';
abstract class TrackedItem {
int? id;
String name;
double amount;
Frequency? frequency;
String description;
TrackedItem({
this.id,
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,
};
}
}