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