firestore_search 0.0.2 firestore_search: ^0.0.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.
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:
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
scaffoldBody |
Widget |
Widget |
No |
This widget will appear in the body of Scaffold. |
appBarBottom |
PreferredSizeWidget |
null |
No |
This widget will appear at the bottom of Search AppBar. |
firestoreCollectionName |
String |
`` | Yes |
Determines the Cloud Firestore collection You want to search in. |
dataListFromSnapshot |
List Function(QuerySnapshot) |
null |
Yes |
This function converts QuerySnapshot to A List of required data. |
builder |
Widget Function(BuildContext, AsyncSnapshot) |
null |
No |
This is the builder function of StreamBuilder used by this widget to show search results. |
limitOfRetrievedData |
int |
10 |
No |
Determines the number of documents returned by the search query. |
CREDITS #
Contributors #
Made with contributors-img.