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:
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user