create project
This commit is contained in:
48
frontend/lib/models/bill.dart
Normal file
48
frontend/lib/models/bill.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
enum BillType { expense, income }
|
||||
|
||||
class Bill {
|
||||
final String id;
|
||||
final String userId;
|
||||
final String? familyId;
|
||||
final BillType type;
|
||||
final double amount;
|
||||
final String category;
|
||||
final String note;
|
||||
final String emoji;
|
||||
final String time;
|
||||
final String date;
|
||||
final String createdAt;
|
||||
|
||||
const Bill({
|
||||
required this.id,
|
||||
required this.userId,
|
||||
this.familyId,
|
||||
required this.type,
|
||||
required this.amount,
|
||||
required this.category,
|
||||
this.note = '',
|
||||
this.emoji = '📝',
|
||||
required this.time,
|
||||
required this.date,
|
||||
this.createdAt = '',
|
||||
});
|
||||
|
||||
bool get isExpense => type == BillType.expense;
|
||||
bool get isIncome => type == BillType.income;
|
||||
|
||||
factory Bill.fromJson(Map<String, dynamic> json) {
|
||||
return Bill(
|
||||
id: json['id'] as String? ?? '',
|
||||
userId: json['userId'] as String? ?? '',
|
||||
familyId: json['familyId'] as String?,
|
||||
type: json['type'] as String? == 'income' ? BillType.income : BillType.expense,
|
||||
amount: (json['amount'] as num?)?.toDouble() ?? 0,
|
||||
category: json['category'] as String? ?? '',
|
||||
note: json['note'] as String? ?? '',
|
||||
emoji: json['emoji'] as String? ?? '📝',
|
||||
time: json['time'] as String? ?? '00:00',
|
||||
date: json['date'] as String? ?? '',
|
||||
createdAt: json['createdAt'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user