DiaryService class
Service responsible for managing diary entries in Firestore and local SQLite.
This class handles:
- Adding and deleting entries in Firestore.
- Fetching diary cards and entries.
- Falling back to local SQLite when Firestore is unavailable.
- Syncing local cache with remote data.
- Handling storage permissions.
Use DiaryService.instance
to access the singleton.
Constructors
- DiaryService()
-
Factory constructor to access the singleton instance.
factory
- DiaryService.test({required FirebaseFirestore firestore, required FirebaseAuth auth, required LocalDiaryDatabase localDb, required GeolocatorService geoService})
- Constructor used for unit testing with injected dependencies.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addEntry(
DiaryEntry entry) → Future< void> - Adds a diary entry to Firestore under the current user's collection.
-
deleteEntry(
String entryId) → Future< void> - Deletes a diary entry from both Firestore and local storage.
-
fetchMoreDiaryEntries(
{QueryDocumentSnapshot< Map< ? lastDocument, required int limit}) → Future<String, dynamic> >List< QueryDocumentSnapshot< >Map< >String, dynamic> > - Loads more diary entries in paginated form from Firestore.
-
getDiaryCards(
{int limit = 10, int offset = 0}) → Future< List< DiaryCard> > - Retrieves a paginated list of diary cards from Firestore.
-
getEntryById(
String entryId) → Future< DiaryEntry?> - Returns a full diary entry by ID, from Firestore or local DB if offline.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
requestStoragePermission(
) → Future< bool> - Requests storage permission required for accessing photos.
-
syncLocalEntriesWithFirestore(
UserCredential userCredential) → Future< void> - Syncs the latest 10 remote entries to local storage on first login.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → DiaryService
-
final