Files
QingTianJiZhang/lib/models/transaction_model.dart

48 lines
1.2 KiB
Dart

class TransactionModel {
final String id;
final double amount;
final String type; // 'income' or 'expense'
final int categoryId;
final DateTime date;
final String? note;
final DateTime createdAt;
final DateTime updatedAt;
TransactionModel({
required this.id,
required this.amount,
required this.type,
required this.categoryId,
required this.date,
this.note,
required this.createdAt,
required this.updatedAt,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'amount': amount,
'type': type,
'categoryId': categoryId,
'date': date.millisecondsSinceEpoch,
'note': note,
'createdAt': createdAt.millisecondsSinceEpoch,
'updatedAt': updatedAt.millisecondsSinceEpoch,
};
}
factory TransactionModel.fromMap(Map<String, dynamic> map) {
return TransactionModel(
id: map['id'],
amount: map['amount'],
type: map['type'],
categoryId: map['categoryId'],
date: DateTime.fromMillisecondsSinceEpoch(map['date']),
note: map['note'],
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt']),
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt']),
);
}
}