Successfully migrate the application to SQLIte!
This commit is contained in:
@ -1,20 +1,24 @@
|
||||
import '/models/frequency.dart';
|
||||
|
||||
class Expense {
|
||||
final int? id;
|
||||
final String name;
|
||||
final double cost;
|
||||
final Frequency frequency;
|
||||
final String description;
|
||||
|
||||
const Expense(
|
||||
{required this.name,
|
||||
required this.cost,
|
||||
required this.frequency,
|
||||
required this.description});
|
||||
const Expense({
|
||||
this.id,
|
||||
required this.name,
|
||||
required this.cost,
|
||||
required this.frequency,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "$name, $cost, ${frequency.title}, $description";
|
||||
//return "$name, $cost, ${frequency.title}, $description";
|
||||
return toMap().toString();
|
||||
}
|
||||
|
||||
double calcComparableCost() {
|
||||
@ -24,4 +28,24 @@ class Expense {
|
||||
double calcComparableCostDaily() {
|
||||
return cost / frequency.numDays;
|
||||
}
|
||||
|
||||
factory Expense.fromMap(Map<String, dynamic> json) => Expense(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
cost: json['cost'],
|
||||
frequency: Frequency.values
|
||||
.where((expense) => expense.title == json['frequency'])
|
||||
.first,
|
||||
description: json['description'],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'cost': cost,
|
||||
'frequency': frequency.title,
|
||||
'description': description,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user