This project has been migrated to the following monorepo and will no longer be maintained here.
An enhanced version of the cloud firestore dart package with support for filtering, sorting, limiting, error handling and success scenarios
- Add Firebase Core as a dependency in your pubspec.yaml file
- In your main.dart file, initialize a firebase app
Read data in a collection
final res = EnhancedFirestore.read(collection: 'users');
Write data to a collection
final res = EnhancedFirestore.write(
collection: 'users',
payload: {
'name': 'John',
'email': 'john@gmail.com',
'age': '45',
},
)
Update data in a collection
final res = EnhancedFirestore.update(
collection: 'users',
payload: {
'name': 'John Cena',
'email': 'johncena@gmail.com',
'age': '46',
},
filters: [
{
'field': 'email',
'filter': FirestoreFilter.isEqualTo,
'value': 'john@gmail.com',
}
]
)
Delete data in a collection
final res = EnhancedFirestore.delete(
collection: 'users',
filters: [
{
'field': 'email',
'filter': FirestoreFilter.isEqualTo,
'value': 'johncena@gmail.com',
}
]
)
- filters - An array of filters to apply on the collection. Specified as a json object list with the following keys ->
- field - The document field to apply the filter on
- filter - The filter type to apply (is an enum of type FirestoreFilter)
- value - The field content to match against
- field - The document field to apply the filter on
- onSuccess - A function which will execute on success scenarios
- onError - A function which will execute on error scenarios
- sorts - An array of sorts to apply on the collection. Specified as a json object list with the following keys ->
- field - The document field to apply the sort on
- descending - A boolean value denoting the sort direction (specify as false to sort in ascending order )
- field - The document field to apply the sort on
- limit - A limit on the number of returned records
-
An empty list of filters on an update function will result in the entire collection being updated
-
An empty list of filters on a delete function will result in the entire collection being deleted
Based on the original cloud_firestore package by Google (https://pub.dev/packages/cloud_firestore)