Added sqlite
This commit is contained in:
parent
73a7c93e64
commit
f01186df79
14 changed files with 784 additions and 382 deletions
|
|
@ -6,6 +6,13 @@ class Vehicle {
|
|||
final String licensePlate;
|
||||
final DateTime updatedAt;
|
||||
|
||||
/// Soft-delete tombstone: null means active. Deleting sets this instead
|
||||
/// of removing the row, so the deletion itself can be merged/synced like
|
||||
/// any other change (newest `updatedAt` wins) instead of silently
|
||||
/// disappearing and later being resurrected by a device that hasn't seen
|
||||
/// the deletion yet.
|
||||
final DateTime? deletedAt;
|
||||
|
||||
Vehicle({
|
||||
required this.id,
|
||||
required this.make,
|
||||
|
|
@ -13,6 +20,7 @@ class Vehicle {
|
|||
required this.color,
|
||||
required this.licensePlate,
|
||||
required this.updatedAt,
|
||||
this.deletedAt,
|
||||
});
|
||||
|
||||
String get displayName => '$color $make $model ($licensePlate)';
|
||||
|
|
@ -23,6 +31,7 @@ class Vehicle {
|
|||
String? color,
|
||||
String? licensePlate,
|
||||
DateTime? updatedAt,
|
||||
DateTime? deletedAt,
|
||||
}) {
|
||||
return Vehicle(
|
||||
id: id,
|
||||
|
|
@ -31,26 +40,29 @@ class Vehicle {
|
|||
color: color ?? this.color,
|
||||
licensePlate: licensePlate ?? this.licensePlate,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
deletedAt: deletedAt ?? this.deletedAt,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
Map<String, Object?> toMap() => {
|
||||
'id': id,
|
||||
'make': make,
|
||||
'model': model,
|
||||
'color': color,
|
||||
'licensePlate': licensePlate,
|
||||
'updatedAt': updatedAt.toIso8601String(),
|
||||
'license_plate': licensePlate,
|
||||
'updated_at': updatedAt.millisecondsSinceEpoch,
|
||||
'deleted_at': deletedAt?.millisecondsSinceEpoch,
|
||||
};
|
||||
|
||||
factory Vehicle.fromJson(Map<String, dynamic> json) => Vehicle(
|
||||
id: json['id'] as String,
|
||||
make: json['make'] as String,
|
||||
model: json['model'] as String,
|
||||
color: json['color'] as String,
|
||||
licensePlate: json['licensePlate'] as String,
|
||||
updatedAt: json['updatedAt'] != null
|
||||
? DateTime.parse(json['updatedAt'] as String)
|
||||
: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
factory Vehicle.fromMap(Map<String, Object?> map) => Vehicle(
|
||||
id: map['id'] as String,
|
||||
make: map['make'] as String,
|
||||
model: map['model'] as String,
|
||||
color: map['color'] as String,
|
||||
licensePlate: map['license_plate'] 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