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