- 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.
43 lines
1.4 KiB
Dart
43 lines
1.4 KiB
Dart
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:travel_mate/models/album_photo.dart';
|
|
|
|
/// Stores shared album photos per trip locally for offline access.
|
|
class AlbumService {
|
|
/// Loads photos for the given trip.
|
|
Future<List<AlbumPhoto>> loadPhotos(String tripId) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final raw = prefs.getString(_key(tripId));
|
|
if (raw == null) return const [];
|
|
try {
|
|
return AlbumPhoto.decodeList(raw);
|
|
} catch (_) {
|
|
await prefs.remove(_key(tripId));
|
|
return const [];
|
|
}
|
|
}
|
|
|
|
/// Saves photo list.
|
|
Future<void> savePhotos(String tripId, List<AlbumPhoto> photos) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setString(_key(tripId), AlbumPhoto.encodeList(photos));
|
|
}
|
|
|
|
/// Adds one photo.
|
|
Future<List<AlbumPhoto>> addPhoto(String tripId, AlbumPhoto photo) async {
|
|
final current = await loadPhotos(tripId);
|
|
final updated = [...current, photo];
|
|
await savePhotos(tripId, updated);
|
|
return updated;
|
|
}
|
|
|
|
/// Deletes a photo.
|
|
Future<List<AlbumPhoto>> deletePhoto(String tripId, String photoId) async {
|
|
final current = await loadPhotos(tripId);
|
|
final updated = current.where((p) => p.id != photoId).toList();
|
|
await savePhotos(tripId, updated);
|
|
return updated;
|
|
}
|
|
|
|
String _key(String tripId) => 'album_$tripId';
|
|
}
|