- 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.
101 lines
2.5 KiB
Dart
101 lines
2.5 KiB
Dart
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();
|
|
}
|
|
}
|