feat: Add services for managing trip-related data
- Implement EmergencyService for handling emergency contacts per trip. - Create GuestFlagService to manage guest mode flags for trips. - Introduce NotificationService with local notification capabilities. - Add OfflineFlagService for managing offline caching flags. - Develop PackingService for shared packing lists per trip. - Implement ReminderService for managing reminders/to-dos per trip. - Create SosService for dispatching SOS events to a backend. - Add StorageService with album image upload functionality. - Implement TransportService for managing transport segments per trip. - Create TripChecklistService for storing and retrieving trip checklists. - Add TripDocumentService for persisting trip documents metadata. test: Add unit tests for new services - Implement tests for AlbumService, BudgetService, EmergencyService, GuestFlagService, PackingService, ReminderService, SosService, TransportService, TripChecklistService, and TripDocumentService. - Ensure tests cover adding, loading, deleting, and handling corrupted payloads for each service.
This commit is contained in:
100
lib/models/album_photo.dart
Normal file
100
lib/models/album_photo.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Represents a shared photo entry in the trip album.
|
||||
///
|
||||
/// Stores a remote [url], optional [caption], and the uploader identifier for
|
||||
/// basic attribution. Persistence is local/offline via JSON helpers.
|
||||
class AlbumPhoto {
|
||||
/// Unique identifier for the photo entry.
|
||||
final String id;
|
||||
|
||||
/// Public or signed URL of the photo.
|
||||
final String url;
|
||||
|
||||
/// Optional caption provided by the user.
|
||||
final String? caption;
|
||||
|
||||
/// Name or ID of the uploader for display.
|
||||
final String? uploadedBy;
|
||||
|
||||
/// Creation timestamp.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Creates an album photo.
|
||||
const AlbumPhoto({
|
||||
required this.id,
|
||||
required this.url,
|
||||
required this.createdAt,
|
||||
this.caption,
|
||||
this.uploadedBy,
|
||||
});
|
||||
|
||||
/// Convenience builder for a new entry.
|
||||
factory AlbumPhoto.newPhoto({
|
||||
required String id,
|
||||
required String url,
|
||||
String? caption,
|
||||
String? uploadedBy,
|
||||
}) {
|
||||
return AlbumPhoto(
|
||||
id: id,
|
||||
url: url,
|
||||
caption: caption,
|
||||
uploadedBy: uploadedBy,
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Copy with updates.
|
||||
AlbumPhoto copyWith({
|
||||
String? id,
|
||||
String? url,
|
||||
String? caption,
|
||||
String? uploadedBy,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return AlbumPhoto(
|
||||
id: id ?? this.id,
|
||||
url: url ?? this.url,
|
||||
caption: caption ?? this.caption,
|
||||
uploadedBy: uploadedBy ?? this.uploadedBy,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// Serialize to JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'url': url,
|
||||
'caption': caption,
|
||||
'uploadedBy': uploadedBy,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Deserialize from JSON.
|
||||
factory AlbumPhoto.fromJson(Map<String, dynamic> json) {
|
||||
return AlbumPhoto(
|
||||
id: json['id'] as String,
|
||||
url: json['url'] as String,
|
||||
caption: json['caption'] as String?,
|
||||
uploadedBy: json['uploadedBy'] as String?,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
/// Encode list to string.
|
||||
static String encodeList(List<AlbumPhoto> photos) {
|
||||
return json.encode(photos.map((p) => p.toJson()).toList());
|
||||
}
|
||||
|
||||
/// Decode list from string.
|
||||
static List<AlbumPhoto> decodeList(String raw) {
|
||||
final decoded = json.decode(raw) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(AlbumPhoto.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
106
lib/models/budget_category.dart
Normal file
106
lib/models/budget_category.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Represents a budget envelope per category with currency awareness.
|
||||
class BudgetCategory {
|
||||
/// Unique identifier of the category entry.
|
||||
final String id;
|
||||
|
||||
/// Category name (hébergement, transport, food, activités...).
|
||||
final String name;
|
||||
|
||||
/// Planned amount.
|
||||
final double planned;
|
||||
|
||||
/// Currency code (ISO 4217) used for the amount.
|
||||
final String currency;
|
||||
|
||||
/// Amount actually spent (to be filled by expenses sync later).
|
||||
final double spent;
|
||||
|
||||
/// Creation timestamp for ordering.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Creates a budget category entry.
|
||||
const BudgetCategory({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.planned,
|
||||
required this.currency,
|
||||
required this.spent,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
/// Convenience constructor for new envelope.
|
||||
factory BudgetCategory.newCategory({
|
||||
required String id,
|
||||
required String name,
|
||||
required double planned,
|
||||
required String currency,
|
||||
}) {
|
||||
return BudgetCategory(
|
||||
id: id,
|
||||
name: name,
|
||||
planned: planned,
|
||||
currency: currency,
|
||||
spent: 0,
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a copy with updated fields.
|
||||
BudgetCategory copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
double? planned,
|
||||
String? currency,
|
||||
double? spent,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return BudgetCategory(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
planned: planned ?? this.planned,
|
||||
currency: currency ?? this.currency,
|
||||
spent: spent ?? this.spent,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// JSON serialization.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'planned': planned,
|
||||
'currency': currency,
|
||||
'spent': spent,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// JSON deserialization.
|
||||
factory BudgetCategory.fromJson(Map<String, dynamic> json) {
|
||||
return BudgetCategory(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
planned: (json['planned'] as num).toDouble(),
|
||||
currency: json['currency'] as String,
|
||||
spent: (json['spent'] as num).toDouble(),
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
/// Encodes a list to JSON string.
|
||||
static String encodeList(List<BudgetCategory> categories) {
|
||||
return json.encode(categories.map((c) => c.toJson()).toList());
|
||||
}
|
||||
|
||||
/// Decodes a list from JSON string.
|
||||
static List<BudgetCategory> decodeList(String raw) {
|
||||
final decoded = json.decode(raw) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(BudgetCategory.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
104
lib/models/checklist_item.dart
Normal file
104
lib/models/checklist_item.dart
Normal file
@@ -0,0 +1,104 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Data model representing a single checklist item for a trip.
|
||||
///
|
||||
/// Each item stores a unique [id], the [label] to display, its completion
|
||||
/// status via [isDone], and optional timestamps to support ordering or
|
||||
/// future reminders. The model includes JSON helpers to simplify
|
||||
/// persistence with `SharedPreferences`.
|
||||
class ChecklistItem {
|
||||
/// Unique identifier of the checklist item.
|
||||
final String id;
|
||||
|
||||
/// Human‑readable text describing the task to complete.
|
||||
final String label;
|
||||
|
||||
/// Indicates whether the task has been completed.
|
||||
final bool isDone;
|
||||
|
||||
/// Creation timestamp used to keep a stable order in the list UI.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Optional due date for the task; can be leveraged by reminders later.
|
||||
final DateTime? dueDate;
|
||||
|
||||
/// Creates a checklist item.
|
||||
const ChecklistItem({
|
||||
required this.id,
|
||||
required this.label,
|
||||
required this.isDone,
|
||||
required this.createdAt,
|
||||
this.dueDate,
|
||||
});
|
||||
|
||||
/// Builds a new item in the pending state with the current timestamp.
|
||||
factory ChecklistItem.newItem({
|
||||
required String id,
|
||||
required String label,
|
||||
DateTime? dueDate,
|
||||
}) {
|
||||
return ChecklistItem(
|
||||
id: id,
|
||||
label: label,
|
||||
isDone: false,
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
dueDate: dueDate,
|
||||
);
|
||||
}
|
||||
|
||||
/// Creates a copy with updated fields while keeping immutability.
|
||||
ChecklistItem copyWith({
|
||||
String? id,
|
||||
String? label,
|
||||
bool? isDone,
|
||||
DateTime? createdAt,
|
||||
DateTime? dueDate,
|
||||
}) {
|
||||
return ChecklistItem(
|
||||
id: id ?? this.id,
|
||||
label: label ?? this.label,
|
||||
isDone: isDone ?? this.isDone,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
dueDate: dueDate ?? this.dueDate,
|
||||
);
|
||||
}
|
||||
|
||||
/// Serializes the item to JSON for storage.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'label': label,
|
||||
'isDone': isDone,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
'dueDate': dueDate?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Deserializes a checklist item from JSON.
|
||||
factory ChecklistItem.fromJson(Map<String, dynamic> json) {
|
||||
return ChecklistItem(
|
||||
id: json['id'] as String,
|
||||
label: json['label'] as String,
|
||||
isDone: json['isDone'] as bool? ?? false,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
dueDate: json['dueDate'] != null
|
||||
? DateTime.tryParse(json['dueDate'] as String)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Encodes a list of checklist items to a JSON string.
|
||||
static String encodeList(List<ChecklistItem> items) {
|
||||
final jsonList = items.map((item) => item.toJson()).toList();
|
||||
return json.encode(jsonList);
|
||||
}
|
||||
|
||||
/// Decodes a list of checklist items from a JSON string.
|
||||
static List<ChecklistItem> decodeList(String jsonString) {
|
||||
final decoded = json.decode(jsonString) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(ChecklistItem.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
100
lib/models/emergency_contact.dart
Normal file
100
lib/models/emergency_contact.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Represents an emergency contact for a trip (person or service).
|
||||
///
|
||||
/// Stores basic contact details and optional notes for quick access during
|
||||
/// critical situations.
|
||||
class EmergencyContact {
|
||||
/// Unique identifier for the contact entry.
|
||||
final String id;
|
||||
|
||||
/// Display name (ex: "Ambassade", "Marie", "Assurance Europ").
|
||||
final String name;
|
||||
|
||||
/// Phone number in international format when possible.
|
||||
final String phone;
|
||||
|
||||
/// Optional description or role (ex: "Assistance médicale", "Famille").
|
||||
final String? note;
|
||||
|
||||
/// Creation timestamp for stable ordering.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Creates an emergency contact entry.
|
||||
const EmergencyContact({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.phone,
|
||||
required this.createdAt,
|
||||
this.note,
|
||||
});
|
||||
|
||||
/// Builds a new contact with current timestamp.
|
||||
factory EmergencyContact.newContact({
|
||||
required String id,
|
||||
required String name,
|
||||
required String phone,
|
||||
String? note,
|
||||
}) {
|
||||
return EmergencyContact(
|
||||
id: id,
|
||||
name: name,
|
||||
phone: phone,
|
||||
note: note,
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a copy with updated fields.
|
||||
EmergencyContact copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? phone,
|
||||
String? note,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return EmergencyContact(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
phone: phone ?? this.phone,
|
||||
note: note ?? this.note,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// Serializes contact to JSON.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'phone': phone,
|
||||
'note': note,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Deserializes contact from JSON.
|
||||
factory EmergencyContact.fromJson(Map<String, dynamic> json) {
|
||||
return EmergencyContact(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
phone: json['phone'] as String,
|
||||
note: json['note'] as String?,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
/// Encodes list to JSON string.
|
||||
static String encodeList(List<EmergencyContact> contacts) {
|
||||
return json.encode(contacts.map((c) => c.toJson()).toList());
|
||||
}
|
||||
|
||||
/// Decodes list from JSON string.
|
||||
static List<EmergencyContact> decodeList(String raw) {
|
||||
final decoded = json.decode(raw) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(EmergencyContact.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
99
lib/models/packing_item.dart
Normal file
99
lib/models/packing_item.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Represents an item in the shared packing list for a trip.
|
||||
///
|
||||
/// Each item stores a [label], completion flag [isPacked], and an optional
|
||||
/// [assignee] to indicate who prend en charge l'item.
|
||||
class PackingItem {
|
||||
/// Unique identifier for the packing entry.
|
||||
final String id;
|
||||
|
||||
/// Text displayed in the list (ex: "Adaptateur US", "Pharmacie").
|
||||
final String label;
|
||||
|
||||
/// Whether the item is already packed.
|
||||
final bool isPacked;
|
||||
|
||||
/// Optional assignee (user id or name) for accountability.
|
||||
final String? assignee;
|
||||
|
||||
/// Creation timestamp for ordering.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Creates a packing item.
|
||||
const PackingItem({
|
||||
required this.id,
|
||||
required this.label,
|
||||
required this.isPacked,
|
||||
required this.createdAt,
|
||||
this.assignee,
|
||||
});
|
||||
|
||||
/// Factory to create a new item in not-packed state.
|
||||
factory PackingItem.newItem({
|
||||
required String id,
|
||||
required String label,
|
||||
String? assignee,
|
||||
}) {
|
||||
return PackingItem(
|
||||
id: id,
|
||||
label: label,
|
||||
assignee: assignee,
|
||||
isPacked: false,
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a copy with modifications.
|
||||
PackingItem copyWith({
|
||||
String? id,
|
||||
String? label,
|
||||
bool? isPacked,
|
||||
String? assignee,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return PackingItem(
|
||||
id: id ?? this.id,
|
||||
label: label ?? this.label,
|
||||
isPacked: isPacked ?? this.isPacked,
|
||||
assignee: assignee ?? this.assignee,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// JSON serialization helper.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'label': label,
|
||||
'isPacked': isPacked,
|
||||
'assignee': assignee,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// JSON deserialization helper.
|
||||
factory PackingItem.fromJson(Map<String, dynamic> json) {
|
||||
return PackingItem(
|
||||
id: json['id'] as String,
|
||||
label: json['label'] as String,
|
||||
isPacked: json['isPacked'] as bool? ?? false,
|
||||
assignee: json['assignee'] as String?,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
/// Encodes list to JSON string.
|
||||
static String encodeList(List<PackingItem> items) {
|
||||
return json.encode(items.map((i) => i.toJson()).toList());
|
||||
}
|
||||
|
||||
/// Decodes list from JSON string.
|
||||
static List<PackingItem> decodeList(String raw) {
|
||||
final decoded = json.decode(raw) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(PackingItem.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
106
lib/models/reminder_item.dart
Normal file
106
lib/models/reminder_item.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Represents a dated reminder or to-do for the trip.
|
||||
class ReminderItem {
|
||||
/// Unique identifier.
|
||||
final String id;
|
||||
|
||||
/// Text to display.
|
||||
final String title;
|
||||
|
||||
/// Optional detailed note.
|
||||
final String? note;
|
||||
|
||||
/// Due date/time (UTC) for the reminder.
|
||||
final DateTime dueAt;
|
||||
|
||||
/// Completion flag.
|
||||
final bool isDone;
|
||||
|
||||
/// Creation timestamp.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Creates a reminder item.
|
||||
const ReminderItem({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.dueAt,
|
||||
required this.isDone,
|
||||
required this.createdAt,
|
||||
this.note,
|
||||
});
|
||||
|
||||
/// Convenience builder for new pending reminder.
|
||||
factory ReminderItem.newItem({
|
||||
required String id,
|
||||
required String title,
|
||||
required DateTime dueAt,
|
||||
String? note,
|
||||
}) {
|
||||
return ReminderItem(
|
||||
id: id,
|
||||
title: title,
|
||||
note: note,
|
||||
dueAt: dueAt,
|
||||
isDone: false,
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Copy with changes.
|
||||
ReminderItem copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? note,
|
||||
DateTime? dueAt,
|
||||
bool? isDone,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return ReminderItem(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
note: note ?? this.note,
|
||||
dueAt: dueAt ?? this.dueAt,
|
||||
isDone: isDone ?? this.isDone,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// JSON serialization.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'note': note,
|
||||
'dueAt': dueAt.toIso8601String(),
|
||||
'isDone': isDone,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// JSON deserialization.
|
||||
factory ReminderItem.fromJson(Map<String, dynamic> json) {
|
||||
return ReminderItem(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
note: json['note'] as String?,
|
||||
dueAt: DateTime.parse(json['dueAt'] as String),
|
||||
isDone: json['isDone'] as bool? ?? false,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
/// Encodes list.
|
||||
static String encodeList(List<ReminderItem> reminders) {
|
||||
return json.encode(reminders.map((r) => r.toJson()).toList());
|
||||
}
|
||||
|
||||
/// Decodes list.
|
||||
static List<ReminderItem> decodeList(String raw) {
|
||||
final decoded = json.decode(raw) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(ReminderItem.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
179
lib/models/transport_segment.dart
Normal file
179
lib/models/transport_segment.dart
Normal file
@@ -0,0 +1,179 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Represents a transport segment (vol/train/bus) tied to a trip.
|
||||
///
|
||||
/// Includes identifiers (PNR/train number), schedule times, status, carrier
|
||||
/// and station/airport codes for display and potential real-time tracking.
|
||||
class TransportSegment {
|
||||
/// Unique identifier for this segment entry.
|
||||
final String id;
|
||||
|
||||
/// Segment type: `flight`, `train`, `bus` (extendable).
|
||||
final String type;
|
||||
|
||||
/// Carrier code (e.g., AF, SN, TGV, OUIGO).
|
||||
final String carrier;
|
||||
|
||||
/// Public number (e.g., AF763, TGV 8401).
|
||||
final String number;
|
||||
|
||||
/// Booking reference / PNR if available.
|
||||
final String? pnr;
|
||||
|
||||
/// Departure code (IATA/CRS) or station name.
|
||||
final String departureCode;
|
||||
|
||||
/// Arrival code (IATA/CRS) or station name.
|
||||
final String arrivalCode;
|
||||
|
||||
/// Planned departure time (UTC).
|
||||
final DateTime departureUtc;
|
||||
|
||||
/// Planned arrival time (UTC).
|
||||
final DateTime arrivalUtc;
|
||||
|
||||
/// Current status string (scheduled/delayed/cancelled/boarding/in_air etc.).
|
||||
final String status;
|
||||
|
||||
/// Gate/platform when known.
|
||||
final String? gate;
|
||||
|
||||
/// Seat assignment if provided.
|
||||
final String? seat;
|
||||
|
||||
/// Created-at timestamp for ordering.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Creates a transport segment entry.
|
||||
const TransportSegment({
|
||||
required this.id,
|
||||
required this.type,
|
||||
required this.carrier,
|
||||
required this.number,
|
||||
required this.departureCode,
|
||||
required this.arrivalCode,
|
||||
required this.departureUtc,
|
||||
required this.arrivalUtc,
|
||||
required this.status,
|
||||
required this.createdAt,
|
||||
this.pnr,
|
||||
this.gate,
|
||||
this.seat,
|
||||
});
|
||||
|
||||
/// Helper to instantiate a new scheduled segment with defaults.
|
||||
factory TransportSegment.newSegment({
|
||||
required String id,
|
||||
required String type,
|
||||
required String carrier,
|
||||
required String number,
|
||||
required String departureCode,
|
||||
required String arrivalCode,
|
||||
required DateTime departureUtc,
|
||||
required DateTime arrivalUtc,
|
||||
String? pnr,
|
||||
String? gate,
|
||||
String? seat,
|
||||
}) {
|
||||
return TransportSegment(
|
||||
id: id,
|
||||
type: type,
|
||||
carrier: carrier,
|
||||
number: number,
|
||||
pnr: pnr,
|
||||
departureCode: departureCode,
|
||||
arrivalCode: arrivalCode,
|
||||
departureUtc: departureUtc,
|
||||
arrivalUtc: arrivalUtc,
|
||||
gate: gate,
|
||||
seat: seat,
|
||||
status: 'scheduled',
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a copy with updated fields.
|
||||
TransportSegment copyWith({
|
||||
String? id,
|
||||
String? type,
|
||||
String? carrier,
|
||||
String? number,
|
||||
String? pnr,
|
||||
String? departureCode,
|
||||
String? arrivalCode,
|
||||
DateTime? departureUtc,
|
||||
DateTime? arrivalUtc,
|
||||
String? status,
|
||||
String? gate,
|
||||
String? seat,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return TransportSegment(
|
||||
id: id ?? this.id,
|
||||
type: type ?? this.type,
|
||||
carrier: carrier ?? this.carrier,
|
||||
number: number ?? this.number,
|
||||
pnr: pnr ?? this.pnr,
|
||||
departureCode: departureCode ?? this.departureCode,
|
||||
arrivalCode: arrivalCode ?? this.arrivalCode,
|
||||
departureUtc: departureUtc ?? this.departureUtc,
|
||||
arrivalUtc: arrivalUtc ?? this.arrivalUtc,
|
||||
status: status ?? this.status,
|
||||
gate: gate ?? this.gate,
|
||||
seat: seat ?? this.seat,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// Serializes the segment to JSON for persistence.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'type': type,
|
||||
'carrier': carrier,
|
||||
'number': number,
|
||||
'pnr': pnr,
|
||||
'departureCode': departureCode,
|
||||
'arrivalCode': arrivalCode,
|
||||
'departureUtc': departureUtc.toIso8601String(),
|
||||
'arrivalUtc': arrivalUtc.toIso8601String(),
|
||||
'status': status,
|
||||
'gate': gate,
|
||||
'seat': seat,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Deserializes a segment from JSON.
|
||||
factory TransportSegment.fromJson(Map<String, dynamic> json) {
|
||||
return TransportSegment(
|
||||
id: json['id'] as String,
|
||||
type: json['type'] as String,
|
||||
carrier: json['carrier'] as String,
|
||||
number: json['number'] as String,
|
||||
pnr: json['pnr'] as String?,
|
||||
departureCode: json['departureCode'] as String,
|
||||
arrivalCode: json['arrivalCode'] as String,
|
||||
departureUtc: DateTime.parse(json['departureUtc'] as String),
|
||||
arrivalUtc: DateTime.parse(json['arrivalUtc'] as String),
|
||||
status: json['status'] as String,
|
||||
gate: json['gate'] as String?,
|
||||
seat: json['seat'] as String?,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
/// Encodes a list of segments to JSON string.
|
||||
static String encodeList(List<TransportSegment> segments) {
|
||||
return json.encode(segments.map((s) => s.toJson()).toList());
|
||||
}
|
||||
|
||||
/// Decodes a list of segments from JSON string.
|
||||
static List<TransportSegment> decodeList(String raw) {
|
||||
final decoded = json.decode(raw) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(TransportSegment.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
123
lib/models/trip_document.dart
Normal file
123
lib/models/trip_document.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
import 'dart:convert';
|
||||
|
||||
/// Represents a document attached to a trip (billet, passeport, assurance, etc.).
|
||||
///
|
||||
/// The model stores a human-friendly [title], a [category] to filter in the UI,
|
||||
/// an optional [downloadUrl] when the file is hosted remotely, and an optional
|
||||
/// [expiresAt] date for reminders (ex: passeport ou ESTA).
|
||||
class TripDocument {
|
||||
/// Unique identifier for the document entry.
|
||||
final String id;
|
||||
|
||||
/// Display name chosen by the user (ex: « Billet retour AF763 »).
|
||||
final String title;
|
||||
|
||||
/// Type/category (ex: `billet`, `passeport`, `assurance`, `hebergement`).
|
||||
final String category;
|
||||
|
||||
/// Optional URL to open/download the document (cloud storage or external).
|
||||
final String? downloadUrl;
|
||||
|
||||
/// Optional local file path when offline-only; kept for future sync.
|
||||
final String? localPath;
|
||||
|
||||
/// Optional expiration date to trigger reminders.
|
||||
final DateTime? expiresAt;
|
||||
|
||||
/// Creation timestamp used for stable ordering.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// Creates a trip document entry.
|
||||
const TripDocument({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.category,
|
||||
required this.createdAt,
|
||||
this.downloadUrl,
|
||||
this.localPath,
|
||||
this.expiresAt,
|
||||
});
|
||||
|
||||
/// Builds a new entry with defaults.
|
||||
factory TripDocument.newEntry({
|
||||
required String id,
|
||||
required String title,
|
||||
required String category,
|
||||
String? downloadUrl,
|
||||
String? localPath,
|
||||
DateTime? expiresAt,
|
||||
}) {
|
||||
return TripDocument(
|
||||
id: id,
|
||||
title: title,
|
||||
category: category,
|
||||
downloadUrl: downloadUrl,
|
||||
localPath: localPath,
|
||||
expiresAt: expiresAt,
|
||||
createdAt: DateTime.now().toUtc(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Returns a copy with updated fields.
|
||||
TripDocument copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? category,
|
||||
String? downloadUrl,
|
||||
String? localPath,
|
||||
DateTime? expiresAt,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return TripDocument(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
category: category ?? this.category,
|
||||
downloadUrl: downloadUrl ?? this.downloadUrl,
|
||||
localPath: localPath ?? this.localPath,
|
||||
expiresAt: expiresAt ?? this.expiresAt,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// Serializes the entry to JSON for persistence.
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'category': category,
|
||||
'downloadUrl': downloadUrl,
|
||||
'localPath': localPath,
|
||||
'expiresAt': expiresAt?.toIso8601String(),
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Deserializes a trip document from JSON.
|
||||
factory TripDocument.fromJson(Map<String, dynamic> json) {
|
||||
return TripDocument(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
category: json['category'] as String,
|
||||
downloadUrl: json['downloadUrl'] as String?,
|
||||
localPath: json['localPath'] as String?,
|
||||
expiresAt: json['expiresAt'] != null
|
||||
? DateTime.tryParse(json['expiresAt'] as String)
|
||||
: null,
|
||||
createdAt: DateTime.parse(json['createdAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
/// Encodes a list of documents to a JSON string.
|
||||
static String encodeList(List<TripDocument> docs) {
|
||||
return json.encode(docs.map((d) => d.toJson()).toList());
|
||||
}
|
||||
|
||||
/// Decodes a list of documents from a JSON string.
|
||||
static List<TripDocument> decodeList(String raw) {
|
||||
final decoded = json.decode(raw) as List<dynamic>;
|
||||
return decoded
|
||||
.cast<Map<String, dynamic>>()
|
||||
.map(TripDocument.fromJson)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user