firestore_db_impl 0.0.2+1
firestore_db_impl: ^0.0.2+1 copied to clipboard
A Flutter package that simplifies Firestore operations by providing structured CRUD methods, query abstraction, custom exceptions, and utility services for timestamps and counters.
firestore_db_impl #
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.
Features #
- 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
Getting Started #
Installation #
Add the following to your pubspec.yaml
:
dependencies:
firestore_db_impl: <latest_version>
Import #
import 'package:firestore_db_impl/firestore_db_impl.dart';
Usage #
Save a Document #
final service = FireStoreDbCrudServiceImpl();
String? docId = await service.saveDocument(
data: {'name': 'John Doe'},
collectionPath: 'users',
);
Update a Document #
await service.updateDocument(
collectionPath: 'users',
id: docId,
data: {'name': 'Jane Doe'},
);
Query Documents #
final queryParams = [
QueryParameter(type: QueryType.where, field: 'role', value: 'admin'),
];
List<Map<String, dynamic>?>? results = await service.getAllDocuments(
collectionPath: 'users',
queryParameters: queryParams,
);
Stream Documents #
Stream<List<Map<String, dynamic>?>?> userStream = service.getStreamAllDocuments(
collectionPath: 'users',
);
Get a Document by ID #
Map<String, dynamic>? user = await service.getDocumentById(
collectionPath: 'users',
id: docId,
);
Extensions #
QueryExtension
: ApplyQueryParameter
to Firestore queriesDocumentSnapshotExtension
: Convert Firestore snapshots to maps or modelsQuerySnapshotExtension
: Convert query results to a list or map
Error Handling #
This package provides a robust error-handling system through custom exceptions:
NoInternetConnectionException
UnauthorizedException
BadResponseFormatException
FireStoreException
, and more
Utility Services #
FireStoreIteratorServiceImpl
: Increment/Decrement field valuesFireStoreTimerServiceImpl
: Server timestamp handling
Dependencies #
cloud_firestore
flutter
License #
MIT License