firestore_search 0.1.2
firestore_search: ^0.1.2 copied to clipboard

This package helps developers to implement cloud_firestore search in their apps.

Firestore Search Scaffold - firestore_search #

This package helps developers in implementation of search on Cloud FireStore. This package comes with the implementation of widgets essential for performing search on a database.

For cloud_firestore: ^0.14.0 use firestore_search: ^0.1.1 #

Activated Search App BAr Searching for Users in Firestore Collection

Pub Version GitHub Workflow Status Github Stars GitHub

Saves You from following implementations #

  • Search AppBar - An AppBar that turns into a TextInputField that takes search queries from users
  • Search Body - A body that shoes up when user starts typing in the Search AppBar
  • Cloud FireStore Queries - Takes user's input and queries the requested CloudFirestore collection

Simple Usage #

To use this plugin, add firestore_search as a dependency in your pubspec.yaml file.

##Implementation:

  • Import import 'package:firestore_search/firestore_search.dart';

  • Create a data model, for the data you want retrieve from Cloud FireStore (Your data model class must contain a function to convert QuerySnapshot from Cloud Firestore to a list of objects of your data model)

class DataModel {
  final String name;
  final String description;

  DataModel({this.name, this.description});

  //Create a method to convert QuerySnapshot from Cloud Firestore to a list of objects of this DataModel
  //This function in essential to the working of FirestoreSearchScaffold

  List<DataModel> **dataListFromSnapshot**(QuerySnapshot querySnapshot) {
    return querySnapshot.docs.map((snapshot) {
      final Map<String, dynamic> dataMap = snapshot.data();

      return DataModel(
          name: dataMap['name'], description: dataMap['description']);
    }).toList();
  }
}
  • Use class FirestoreSearchScaffold and provide the required parameters
FirestoreSearchScaffold(
        dataListFromSnapshot: UserData().userListFromSnapshot,
        firestoreCollectionName: 'users',
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return Center(
              child: Text('Snapshot has data'),
            );
          } else if (snapshot.hasError) {
            return Center(
              child: Text('Snapshot has data'),
            );
          }
          return Center(
            child: CircularProgressIndicator(),
          );
        },
        ));
                                                                                  ##You are good to go!

In order to add the FirestoreSearchScaffold in your app, there are several attributes that are important and neglecting them or treating them roughly might throw errors:

AttributeTypeDefaultRequiredDescription
scaffoldBodyWidgetWidgetNoThis widget will appear in the body of Scaffold.
appBarBottomPreferredSizeWidgetnullNoThis widget will appear at the bottom of Search AppBar.
firestoreCollectionNameString``YesDetermines the Cloud Firestore collection You want to search in.
searchByString``YesKey for the firestore_collection value you want to search by.
dataListFromSnapshotList Function(QuerySnapshot)nullYesThis function converts QuerySnapshot to A List of required data.
builderWidget Function(BuildContext, AsyncSnapshot)nullNoThis is the builder function of StreamBuilder used by this widget to show search results.
limitOfRetrievedDataint10NoDetermines the number of documents returned by the search query.

CREDITS #

Contributors #

Made with contributors-img.

6
likes
90
pub points
72%
popularity

This package helps developers to implement cloud_firestore search in their apps.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

wecreatelegacy@gmail.com

License

MIT (LICENSE)

Dependencies

cloud_firestore, flutter

More

Packages that depend on firestore_search