firebase_utils 1.0.1 copy "firebase_utils: ^1.0.1" to clipboard
firebase_utils: ^1.0.1 copied to clipboard

Range of utilities for Firestore and Fire Storage, including CRUD operations and other essential functions

Firebase Utils #

pub package license

This package offers a range of utilities for Firestore and Fire Storage, including CRUD operations and other essential functions. You can easily perform common database operations and efficiently store and manage data, allowing you to focus on developing the core functionality of your app.

Installation #

To use Firebase Utils in your project, add the following dependency to your pubspec.yaml file

dependencies:
  firebase_utils: ^<latest-version>
copied to clipboard

Then run flutter pub get to install the package.

Example #

ezgif com-resize

Usage #

Firestore Utilities #

Import the package in your Dart code

import 'package:firebase_utils/entity/firestore_doc.dart';
import 'package:firebase_utils/firebase/firestore_service.dart';
copied to clipboard

Create an Entity UserInfo which can extends FireStoreDoc or TimeStampedFireStoreDoc. If you need createdDate and updatedDate fields in firestore table then extends with TimeStampedFireStoreDoc.

class UserInfo extends FireStoreDoc {
  final String name;
  final String email;
  final String profileImage;

  UserInfo(
      {required this.name, required this.email, required this.profileImage});

  @override
  Map<String, dynamic> toMap() => <String, dynamic>{
        'name': name,
        'email': email,
        'profileImage': profileImage,
      };

  factory UserInfo.fromMap(Map<String, dynamic> map) => UserInfo(
        name: map['name'] as String,
        email: map['email'] as String,
        profileImage: map['profileImage'] as String,
      );
}
copied to clipboard

Create a collection reference of users. users is a collection type of UserInfo in firestore db

CollectionReference<UserInfo> get _userCollectionRef =>
      widget._fireStoreService.getCollectionRef(
          'users', (snapshot, _) => UserInfo.fromMap(snapshot.data()!));
copied to clipboard

Get a instance of FireStoreService to perform all Firestore operations.

final FireStoreService firestoreService =  FireStoreService.getInstance(FirebaseFirestore.instance)
copied to clipboard

Fetch all documents of collection in Streams

firestoreService.getListStream(_userCollectionRef).listen((event) {
    List<UserInfo> = event
})
copied to clipboard

Insert data

firestoreService.add(UserInfo(name: 'abc',email: 'abc@gmail.com',profileImage:'imageUrl'),_userCollectionRef)
copied to clipboard

Delete Object

await fireStoreService.delete(_userCollectionRef.doc(docId));
copied to clipboard

You can use all other functions for Firestore operations defined in FireStoreService.

FirebaseStorage Utilities #

Import the package in your Dart code

import 'package:firebase_utils/firebase/firebase_storage_service.dart';
copied to clipboard

Get a instance of FirebaseStorageService to perform all FirebaseStorage operations.

final FirebaseStorageService firebaseStorageService =  FirebaseStorageService.getInstance( FirebaseStorage.instance)
copied to clipboard

Upload a file

firebaseStorageService.updateFileAndGetUrl(downloadUrl, file)
copied to clipboard

Author #

DevCrew.IO

Connect with Us:

devcrew.io mycompany DevCrew-io

Contributing #

Contributions, issues, and feature requests are welcome!

Show your Support #

Give a star if this project helped you.

Bugs and feature requests #

Have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Code copyright 2023–2024 DevCrew I/O. Code released under the MIT license.

6
likes
140
points
41
downloads

Publisher

verified publisherdevcrew.io

Weekly Downloads

2024.09.14 - 2025.03.29

Range of utilities for Firestore and Fire Storage, including CRUD operations and other essential functions

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

cloud_firestore, firebase_storage, flutter

More

Packages that depend on firebase_utils