feat:"初始化仓库,并更新基础代码。"
This commit is contained in:
47
lib/models/transaction_model.dart
Normal file
47
lib/models/transaction_model.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
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']),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user