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:
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user