FirestoreApi<T extends Object> constructor
- required FirebaseFirestore firebaseFirestore,
- required String collectionPath(),
- Map<
String, dynamic> toJson(- T value
- T fromJson()?,
- T fromJsonError()?,
- bool tryAddLocalId = false,
- FeedbackConfig feedbackConfig = const FeedbackConfig(),
- FirestoreLogger firestoreLogger = const FirestoreDefaultLogger(),
- String createdFieldName = 'created',
- String updatedFieldName = 'updated',
- String idFieldName = 'id',
- String documentReferenceFieldName = 'documentReference',
- bool isCollectionGroup = false,
- bool tryAddLocalDocumentReference = false,
- GetOptions? getOptions,
- SensitiveLogLevel sensitiveLogLevel = SensitiveLogLevel.info,
The FirestoreApi requires only a firebaseFirestore
instance and a collectionPath
to
work initially.
If you are interested in using the 'WithConverter' methods that automatically convert your
data to specific models of T
then define both the toJson
and fromJson
.
If tryAddLocalId
is true then your data will have an id field added based on the
idFieldName
. Add this id field to the model you're serializing to and you
will have easy access to the document id at any time. Any create or update method will by
default try te remove the field again before writing to Firestore (unless specified otherwise
inside the method).
If you are interested in providing custom feedback to your users then provide your own
instance of the feedbackConfig
. This config contains specific feedback messages regarding
successful and unsuccessful CRUD operations of a certain collection.
The firestoreLogger
is used to provide proper logging when performing any operation inside
the FirestoreApi. Implement your own version in order to use to use your own logging system.
Implementation
FirestoreApi({
required FirebaseFirestore firebaseFirestore,
required String Function() collectionPath,
Map<String, dynamic> Function(T value)? toJson,
T Function(Map<String, dynamic> json)? fromJson,
T Function(Map<String, dynamic> json)? fromJsonError,
bool tryAddLocalId = false,
FeedbackConfig feedbackConfig = const FeedbackConfig(),
FirestoreLogger firestoreLogger = const FirestoreDefaultLogger(),
String createdFieldName = 'created',
String updatedFieldName = 'updated',
String idFieldName = 'id',
String documentReferenceFieldName = 'documentReference',
bool isCollectionGroup = false,
bool tryAddLocalDocumentReference = false,
GetOptions? getOptions,
SensitiveLogLevel sensitiveLogLevel = SensitiveLogLevel.info,
}) : _firebaseFirestore = firebaseFirestore,
_collectionPath = collectionPath,
_toJson = toJson,
_fromJson = fromJson,
_fromJsonError = fromJsonError,
_tryAddLocalId = tryAddLocalId,
_responseConfig = feedbackConfig.responseConfig,
_log = firestoreLogger,
_createdFieldName = createdFieldName,
_updatedFieldName = updatedFieldName,
_idFieldName = idFieldName,
_documentReferenceFieldName = documentReferenceFieldName,
_isCollectionGroup = isCollectionGroup,
_tryAddLocalDocumentReference = tryAddLocalDocumentReference,
_getOptions = getOptions,
_sensitiveLogLevel = sensitiveLogLevel;