Remote sync of webdav

This commit is contained in:
Courtney Arnold 2026-08-13 17:05:10 -05:00
parent f01186df79
commit 483fbeafb6
44 changed files with 4842 additions and 975 deletions

View file

@ -1,9 +1,19 @@
class Vehicle {
/// Hidden, immutable, generated primary key — never shown in the UI and
/// never editable. This is what fuel entries actually reference and what
/// sync merges on, so that [vin] itself is free to be edited without
/// breaking those references or losing sync history.
final String id;
final String make;
final String model;
final String color;
final String licensePlate;
/// The vehicle's identification number. Required and must be unique
/// among active (non-deleted) vehicles, but — unlike [id] — the user can
/// edit it later (e.g. to fix a typo from a misread VIN scan).
final String vin;
/// User-chosen label, e.g. "Mom's Car" or "Red Ford F-150". Optional —
/// when absent, screens fall back to other identifying info instead.
final String? nickname;
final DateTime updatedAt;
/// Soft-delete tombstone: null means active. Deleting sets this instead
@ -15,30 +25,35 @@ class Vehicle {
Vehicle({
required this.id,
required this.make,
required this.model,
required this.color,
required this.licensePlate,
required this.vin,
required this.updatedAt,
this.nickname,
this.deletedAt,
});
String get displayName => '$color $make $model ($licensePlate)';
/// What screens should show as the vehicle's primary label: the nickname
/// if one was given, otherwise the VIN itself.
String get displayLabel {
final trimmedNickname = nickname?.trim();
if (trimmedNickname != null && trimmedNickname.isNotEmpty) {
return trimmedNickname;
}
return vin;
}
/// Note: [id] is intentionally not overridable here — it's the hidden
/// identifier, not an editable field.
Vehicle copyWith({
String? make,
String? model,
String? color,
String? licensePlate,
String? vin,
String? nickname,
bool clearNickname = false,
DateTime? updatedAt,
DateTime? deletedAt,
}) {
return Vehicle(
id: id,
make: make ?? this.make,
model: model ?? this.model,
color: color ?? this.color,
licensePlate: licensePlate ?? this.licensePlate,
vin: vin ?? this.vin,
nickname: clearNickname ? null : (nickname ?? this.nickname),
updatedAt: updatedAt ?? this.updatedAt,
deletedAt: deletedAt ?? this.deletedAt,
);
@ -46,20 +61,16 @@ class Vehicle {
Map<String, Object?> toMap() => {
'id': id,
'make': make,
'model': model,
'color': color,
'license_plate': licensePlate,
'vin': vin,
'nickname': nickname,
'updated_at': updatedAt.millisecondsSinceEpoch,
'deleted_at': deletedAt?.millisecondsSinceEpoch,
};
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,
vin: map['vin'] as String,
nickname: map['nickname'] 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)