firestore_db_impl is a Flutter package that provides an implementation layer over Firebase Cloud Firestore for easier and more consistent CRUD operations, querying, and error handling. It aims to reduce boilerplate and standardize interactions with Firestore, allowing developers to focus more on business logic.
- Simplified Firestore CRUD operations
- Stream and Future-based data retrieval
- Structured exception handling
- Query parameter abstraction with enums
- Firestore timestamp and counter utilities
- Extensible and modular architecture
Add the following to your pubspec.yaml:
dependencies:
firestore_db_impl: <latest_version>import 'package:firestore_db_impl/firestore_db_impl.dart';final service = FireStoreDbCrudServiceImpl();
String? docId = await service.saveDocument(
data: {'name': 'John Doe'},
collectionPath: 'users',
);await service.updateDocument(
collectionPath: 'users',
id: docId,
data: {'name': 'Jane Doe'},
);final queryParams = [
QueryParameter(type: QueryType.where, field: 'role', value: 'admin'),
];
List<Map<String, dynamic>?>? results = await service.getAllDocuments(
collectionPath: 'users',
queryParameters: queryParams,
);Stream<List<Map<String, dynamic>?>?> userStream = service.getStreamAllDocuments(
collectionPath: 'users',
);Map<String, dynamic>? user = await service.getDocumentById(
collectionPath: 'users',
id: docId,
);QueryExtension: ApplyQueryParameterto Firestore queriesDocumentSnapshotExtension: Convert Firestore snapshots to maps or modelsQuerySnapshotExtension: Convert query results to a list or map
This package provides a robust error-handling system through custom exceptions:
NoInternetConnectionExceptionUnauthorizedExceptionBadResponseFormatExceptionFireStoreException, and more
FireStoreIteratorServiceImpl: Increment/Decrement field valuesFireStoreTimerServiceImpl: Server timestamp handling
cloud_firestoreflutter
MIT License