FirebaseDatabaseService class
FirebaseDatabaseService This class provides the access and management tools for the app's Firebase Realtime Database. It heavily leverages the FirebaseDatabase class for certain functions:
- reading
- deleting
- updating
- inserting
The pattern for these methods is rather repetitive. We begin by creating a reference to the location in the db we wish to access we then retrieve that reference using .once() we then use .then() as a callback which will be triggered once the db has returned the data to us (either from local cache or the cloud) Finally, we process the data and return it as an object (which is wrapped in a Future!)
We also need to handle errors that may occur
- Inheritance
- Object
- ChangeNotifier
- FirebaseDatabaseService
Constructors
- FirebaseDatabaseService()
- when this object is instantiated then configure the following offline parameters enable persistence - the database can now be cached locally and still utilised as if it were online set the size of the cache to 10 mb
Properties
- database ↔ FirebaseDatabase
-
read / write
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- hasListeners → bool
-
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes. [...]
inherited
-
addValidatedDonorNumber(
String email, String donorNumber) → Future - Add a validated donor number to a particular user account. This stores their validated donor number within their account details
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener and removeListener will throw after the object is
disposed). [...]
@mustCallSuper, inherited
-
getAllArticles(
) → Future< Map< String, List< >EducationArticle> > - Read all of the articles from the database and return a map containing the category and the respective list of articles
-
getArticles(
String category) → Future< List< EducationArticle> > - Retrieve the articles of a particular category from the database
-
getDepots(
) → Future< List< Depot> > - Retrieve the list of depots from the database
-
getDonorUser(
String email) → Future - Retrieve a donor user by their email address
-
getNewsAndEvents(
) → Future< List< NewsAndEventsItem> > - Retrieve the news and events items from the database
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
notifyListeners(
) → void -
Call all the registered listeners. [...]
@protected, @visibleForTesting, inherited
-
pushDonationDropoff(
DonationDropoff donationDropoff) → Future - Write a donation dropoff to the database
-
pushNewDonorUser(
String email, String fullName, String phoneNumber) → Future - write a new donor user to the database using the provided data
-
pushSuggestedArticle(
SuggestedArticle suggestedArticle) → Future - Write a suggested article to the firebase database
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes. [...]
inherited
-
setNewUserDonorStatus(
String email) → Future - Determines whether a newly registered user is already an active donor, If so then add the donor number to their user account data
-
toString(
) → String -
Returns a string representation of this object.
inherited
-
validateDonorNumber(
String email, String donorNumber) → Future - Validate whether a donor number exists for a particular account (email address)
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited