3. Firestore
• Used to
• Store data
• Add data
• Modify data
• Delete data
• Firestore Store data as Documents and each Document inside a
collection
4. Reading data from Firestore collection as stream
• In the class Databasemethods which we have created earlier we can
add a new function to read the whole data of a collection.
Future<Stream<QuerySnapshot>> getData(String CollectionName) async{
return await FirebaseFirestore.instance.collection(CollectionName).snapshots();
}
uture<Stream<QuerySnapshot>> getData(String CollectionName) async{
return await fdb
.collection(CollectionName)
.snapshots();
}
FirebaseFirestore fdb = FirebaseFirestore.instance;
6. Uses of initState():
• initState() is a method of class State and it is considered as an
important lifecycle method in Flutter. initState() is called the only
once and we use it for one-time initializations.
• Example :
• To initialize data that depends on the specific BuildContext.
• To initialize data that need to execute before build()
• Subscribe to Streams.
• initState() is called once and only once. It must also
call super.initState()
7. Building the vessel for the data
Widget allLecDetails(){
return StreamBuilder(
>>> Stream builder settings <<<
? ListView.builder(
>>>ListView setting<<<
return Material(
>>> the card or material elements<<<
);
}):Container();
});
}
>>> Stream builder settings <<<
return StreamBuilder(
stream: LecturerStream,
builder:(context, AsyncSnapshot snapshot){
return snapshot.hasData
? ListView.builder(
>>>ListView setting<<<
? ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index){
DocumentSnapshot ds=snapshot.data.docs[index];
return Material(
8. StreamBuilder
• A StreamBuilder in Flutter is used to listen to a stream of data
and rebuild its widget subtree whenever new data is emitted by the
stream. It’s commonly used for real-time updates, such as when
working with streams of data from network requests, databases, or
other asynchronous sources.
11. Read and show some specific data in a stream
Future<Stream<QuerySnapshot>> getselectedData
(String CollectionName,String docname,String docvalue) async{
return await FirebaseFirestore.instance
.collection(CollectionName)
.where(docname, isEqualTo: docvalue)
.snapshots();
}