FirestoreApi<T extends Object> constructor

FirestoreApi<T extends Object>({
  1. required FirebaseFirestore firebaseFirestore,
  2. required String collectionPath(),
  3. Map<String, dynamic> toJson(
    1. T value
    )?,
  4. T fromJson(
    1. Map<String, dynamic> json
    )?,
  5. T fromJsonError(
    1. Map<String, dynamic> json
    )?,
  6. bool tryAddLocalId = false,
  7. FeedbackConfig feedbackConfig = const FeedbackConfig(),
  8. FirestoreLogger firestoreLogger = const FirestoreDefaultLogger(),
  9. String createdFieldName = 'created',
  10. String updatedFieldName = 'updated',
  11. String idFieldName = 'id',
  12. String documentReferenceFieldName = 'documentReference',
  13. bool isCollectionGroup = false,
  14. bool tryAddLocalDocumentReference = false,
  15. GetOptions? getOptions,
  16. 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;