Added sqlite
This commit is contained in:
parent
73a7c93e64
commit
f01186df79
14 changed files with 784 additions and 382 deletions
|
|
@ -9,6 +9,10 @@ class FuelEntry {
|
|||
final String? receiptDriveFileId;
|
||||
final DateTime updatedAt;
|
||||
|
||||
/// Soft-delete tombstone: null means active. See [Vehicle.deletedAt] for
|
||||
/// why this is a flag rather than an actual row deletion.
|
||||
final DateTime? deletedAt;
|
||||
|
||||
FuelEntry({
|
||||
required this.id,
|
||||
required this.vehicleId,
|
||||
|
|
@ -19,6 +23,7 @@ class FuelEntry {
|
|||
required this.updatedAt,
|
||||
this.receiptImagePath,
|
||||
this.receiptDriveFileId,
|
||||
this.deletedAt,
|
||||
});
|
||||
|
||||
/// True once the receipt photo has been uploaded to Drive and the local
|
||||
|
|
@ -27,13 +32,16 @@ class FuelEntry {
|
|||
receiptImagePath == null && receiptDriveFileId != null;
|
||||
|
||||
/// True while a receipt photo exists only locally and still needs to be
|
||||
/// uploaded next sync.
|
||||
/// uploaded next sync. A row in this state is never pushed to Drive as-is
|
||||
/// (a local file path is meaningless on another device) — sync uploads
|
||||
/// the image first, which clears this.
|
||||
bool get hasPendingLocalReceipt => receiptImagePath != null;
|
||||
|
||||
FuelEntry copyWith({
|
||||
String? receiptImagePath,
|
||||
String? receiptDriveFileId,
|
||||
DateTime? updatedAt,
|
||||
DateTime? deletedAt,
|
||||
bool clearReceiptImagePath = false,
|
||||
}) {
|
||||
return FuelEntry(
|
||||
|
|
@ -47,32 +55,35 @@ class FuelEntry {
|
|||
receiptImagePath:
|
||||
clearReceiptImagePath ? null : (receiptImagePath ?? this.receiptImagePath),
|
||||
receiptDriveFileId: receiptDriveFileId ?? this.receiptDriveFileId,
|
||||
deletedAt: deletedAt ?? this.deletedAt,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
Map<String, Object?> toMap() => {
|
||||
'id': id,
|
||||
'vehicleId': vehicleId,
|
||||
'date': date.toIso8601String(),
|
||||
'vehicle_id': vehicleId,
|
||||
'date': date.millisecondsSinceEpoch,
|
||||
'gallons': gallons,
|
||||
'pricePerGallon': pricePerGallon,
|
||||
'totalCost': totalCost,
|
||||
'receiptImagePath': receiptImagePath,
|
||||
'receiptDriveFileId': receiptDriveFileId,
|
||||
'updatedAt': updatedAt.toIso8601String(),
|
||||
'price_per_gallon': pricePerGallon,
|
||||
'total_cost': totalCost,
|
||||
'receipt_image_path': receiptImagePath,
|
||||
'receipt_drive_file_id': receiptDriveFileId,
|
||||
'updated_at': updatedAt.millisecondsSinceEpoch,
|
||||
'deleted_at': deletedAt?.millisecondsSinceEpoch,
|
||||
};
|
||||
|
||||
factory FuelEntry.fromJson(Map<String, dynamic> json) => FuelEntry(
|
||||
id: json['id'] as String,
|
||||
vehicleId: json['vehicleId'] as String,
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
gallons: (json['gallons'] as num).toDouble(),
|
||||
pricePerGallon: (json['pricePerGallon'] as num).toDouble(),
|
||||
totalCost: (json['totalCost'] as num).toDouble(),
|
||||
receiptImagePath: json['receiptImagePath'] as String?,
|
||||
receiptDriveFileId: json['receiptDriveFileId'] as String?,
|
||||
updatedAt: json['updatedAt'] != null
|
||||
? DateTime.parse(json['updatedAt'] as String)
|
||||
: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
factory FuelEntry.fromMap(Map<String, Object?> map) => FuelEntry(
|
||||
id: map['id'] as String,
|
||||
vehicleId: map['vehicle_id'] as String,
|
||||
date: DateTime.fromMillisecondsSinceEpoch(map['date'] as int),
|
||||
gallons: (map['gallons'] as num).toDouble(),
|
||||
pricePerGallon: (map['price_per_gallon'] as num).toDouble(),
|
||||
totalCost: (map['total_cost'] as num).toDouble(),
|
||||
receiptImagePath: map['receipt_image_path'] as String?,
|
||||
receiptDriveFileId: map['receipt_drive_file_id'] as String?,
|
||||
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updated_at'] as int, isUtc: true),
|
||||
deletedAt: map['deleted_at'] != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(map['deleted_at'] as int, isUtc: true)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue