SlideShare a Scribd company logo
2
Most read
3
Most read
Advance Mobile Application
Development
Firebase part 2
Dr. Mazin Alkathiri
IT Department
Seiyun University
2023-2024
Future addAnyData(Map<String, dynamic> ListMap, String id, String CollectionName)async{
return await FirebaseFirestore.instance
.collection(CollectionName)
.doc(id)
.set(ListMap);
}
Future addData(Map<String, dynamic> DoctorsInfoMap, String id)async{
return await FirebaseFirestore.instance
.collection("lecturer")
.doc(id)
.set(LecInfoMap);
}
Firestore
• Used to
• Store data
• Add data
• Modify data
• Delete data
• Firestore Store data as Documents and each Document inside a
collection
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;
Stream? LecturerStream;
getontheload() async{
LecturerStream=await Databasemethods().getData("lecturer");
setState(() {
});
}
@override
void initState() {
getontheload();
super.initState();
}
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()
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(
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.
return Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(10),
child: Container(
padding: EdgeInsets.all(20),
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(10)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("name : "+ds["lecName"],
style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ),
Text("college : "+ds["lecCol"],
style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ),
Text("Department : "+ds["lecDept"],
style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ),
Text("Phone No. : "+ds["lecPhNo"],
style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ),
],
),
),
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(“Lecturers of Seiyun University"),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Expanded(child: allLecDetails()),
]
)
)
);
}
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();
}
child: Column(
children: [
TextField(
controller: collectionname,
),
TextField(
controller: docname,
),
TextField(
controller: docvalue,
),
ElevatedButton(
child: Text(
"‫"بحث‬,
style: TextStyle(
fontSize: 16.0,
),
),
),
]
)
onPressed: () async{
LecturerStream=await Databasemethods()
.getselectedData(collectionname.text,docname.text,docvalue.text)
.then((value) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Showdata(LecturerStream: value),
),
);
});
}
Updating data
Future updateData
(Map<String, dynamic> ListMap, String id, String CollectionName)async{
return await FirebaseFirestore.instance
.collection(CollectionName)
.doc(id)
.update(ListMap);
}
Future deleteData
(String id, String CollectionName)async{
return await FirebaseFirestore.instance
.collection(CollectionName)
.doc(id)
.delete();
}

More Related Content

PPTX
MySql Interface database in sql python my.pptx
PDF
Getting Started with MongoDB: 4 Application Designs
PDF
Real-Time Spark: From Interactive Queries to Streaming
PPT
Coherence SIG: Advanced usage of indexes in coherence
PDF
09.Local Database Files and Storage on WP
PDF
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
PDF
Intake 37 linq3
PPTX
Whats New for WPF in .NET 4.5
MySql Interface database in sql python my.pptx
Getting Started with MongoDB: 4 Application Designs
Real-Time Spark: From Interactive Queries to Streaming
Coherence SIG: Advanced usage of indexes in coherence
09.Local Database Files and Storage on WP
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
Intake 37 linq3
Whats New for WPF in .NET 4.5

Similar to Advance Mobile Application Development class 05 (20)

PDF
What's new with Apache Spark's Structured Streaming?
PDF
GraphQL Bangkok Meetup 2.0
PPT
DataFinder concepts and example: General (20100503)
PPTX
Kafka Summit NYC 2017 - Easy, Scalable, Fault-tolerant Stream Processing with...
PPTX
Android writing and reading from firebase
PDF
Apache Kafka, and the Rise of Stream Processing
PPTX
PyCon SG x Jublia - Building a simple-to-use Database Management tool
PDF
Java Configuration Deep Dive with Spring
PPT
Lecture14Slides.ppt
PPT
the .NET Framework. It provides the claf
PPTX
Chapter 3: ado.net
PPTX
At the core you will have KUSTO
PDF
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
PDF
Modern Android app library stack
PDF
Spark what's new what's coming
PDF
Simpan data- ke- database
PDF
Beyond SQL: Speeding up Spark with DataFrames
PPTX
Data visualization in python/Django
PPTX
Cloudbase.io MoSync Reload Course
PDF
Getting your data in and out of elasticsearch: let me count the ways
What's new with Apache Spark's Structured Streaming?
GraphQL Bangkok Meetup 2.0
DataFinder concepts and example: General (20100503)
Kafka Summit NYC 2017 - Easy, Scalable, Fault-tolerant Stream Processing with...
Android writing and reading from firebase
Apache Kafka, and the Rise of Stream Processing
PyCon SG x Jublia - Building a simple-to-use Database Management tool
Java Configuration Deep Dive with Spring
Lecture14Slides.ppt
the .NET Framework. It provides the claf
Chapter 3: ado.net
At the core you will have KUSTO
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Modern Android app library stack
Spark what's new what's coming
Simpan data- ke- database
Beyond SQL: Speeding up Spark with DataFrames
Data visualization in python/Django
Cloudbase.io MoSync Reload Course
Getting your data in and out of elasticsearch: let me count the ways
Ad

More from Dr. Mazin Mohamed alkathiri (20)

PPTX
Computer Introduction (Operating Systems)-Lecture06
PPTX
Mobile Application Development (local database) class-07
PPTX
Mobile Application Development (Shared Preferences) class-06
PPTX
Mobile Application Development((Handling User Input and Navigation) class-05
PPTX
Computer Introduction (Data Encryption)-Lecture05
PPTX
Computer Introduction (Computer Viruses )-Lecture04
PPTX
Mobile Applications Development class 04-Layout-04
DOCX
Appendix to Lecture 3 Building a flutter app
PPTX
Mobile Applications Development class 03-starting with flutter
PPTX
Mobile Applications Development class 02 ntroduction to Drat
PPTX
Computer Introduction (Software)-Lecture03
PPTX
Computer Introduction (Hardware)-Lecture02
PPTX
Computer Introduction (introduction)-Lecture01
PPTX
Introduction to Academic Writing class 0-1
PPTX
Mobile Applications Development class 01 - Introduction
PPT
OS-operating systems- ch05 (CPU Scheduling) ...
PPTX
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
PPTX
Advance Mobile Application Development class 07
PPTX
ESSENTIAL of (CS/IT/IS) class 06 (database)
PPT
OS-operating systems- ch04 (Threads) ...
Computer Introduction (Operating Systems)-Lecture06
Mobile Application Development (local database) class-07
Mobile Application Development (Shared Preferences) class-06
Mobile Application Development((Handling User Input and Navigation) class-05
Computer Introduction (Data Encryption)-Lecture05
Computer Introduction (Computer Viruses )-Lecture04
Mobile Applications Development class 04-Layout-04
Appendix to Lecture 3 Building a flutter app
Mobile Applications Development class 03-starting with flutter
Mobile Applications Development class 02 ntroduction to Drat
Computer Introduction (Software)-Lecture03
Computer Introduction (Hardware)-Lecture02
Computer Introduction (introduction)-Lecture01
Introduction to Academic Writing class 0-1
Mobile Applications Development class 01 - Introduction
OS-operating systems- ch05 (CPU Scheduling) ...
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
Advance Mobile Application Development class 07
ESSENTIAL of (CS/IT/IS) class 06 (database)
OS-operating systems- ch04 (Threads) ...
Ad

Recently uploaded (20)

PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Yogi Goddess Pres Conference Studio Updates
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
master seminar digital applications in india
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Complications of Minimal Access Surgery at WLH
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Classroom Observation Tools for Teachers
PDF
01-Introduction-to-Information-Management.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Chinmaya Tiranga quiz Grand Finale.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Yogi Goddess Pres Conference Studio Updates
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
master seminar digital applications in india
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
RMMM.pdf make it easy to upload and study
Complications of Minimal Access Surgery at WLH
Paper A Mock Exam 9_ Attempt review.pdf.
Anesthesia in Laparoscopic Surgery in India
A systematic review of self-coping strategies used by university students to ...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Classroom Observation Tools for Teachers
01-Introduction-to-Information-Management.pdf

Advance Mobile Application Development class 05

  • 1. Advance Mobile Application Development Firebase part 2 Dr. Mazin Alkathiri IT Department Seiyun University 2023-2024
  • 2. Future addAnyData(Map<String, dynamic> ListMap, String id, String CollectionName)async{ return await FirebaseFirestore.instance .collection(CollectionName) .doc(id) .set(ListMap); } Future addData(Map<String, dynamic> DoctorsInfoMap, String id)async{ return await FirebaseFirestore.instance .collection("lecturer") .doc(id) .set(LecInfoMap); }
  • 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;
  • 5. Stream? LecturerStream; getontheload() async{ LecturerStream=await Databasemethods().getData("lecturer"); setState(() { }); } @override void initState() { getontheload(); super.initState(); }
  • 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.
  • 9. return Material( elevation: 5.0, borderRadius: BorderRadius.circular(10), child: Container( padding: EdgeInsets.all(20), width: MediaQuery.of(context).size.width, decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(10)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text("name : "+ds["lecName"], style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ), Text("college : "+ds["lecCol"], style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ), Text("Department : "+ds["lecDept"], style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ), Text("Phone No. : "+ds["lecPhNo"], style:TextStyle(color: Colors.blue,fontSize: 20.0, fontWeight: FontWeight.bold) ), ], ), ), );
  • 10. @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(“Lecturers of Seiyun University"), ), body: Padding( padding: const EdgeInsets.all(16.0), child: Column( children: [ Expanded(child: allLecDetails()), ] ) ) ); }
  • 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(); }
  • 12. child: Column( children: [ TextField( controller: collectionname, ), TextField( controller: docname, ), TextField( controller: docvalue, ), ElevatedButton( child: Text( "‫"بحث‬, style: TextStyle( fontSize: 16.0, ), ), ), ] ) onPressed: () async{ LecturerStream=await Databasemethods() .getselectedData(collectionname.text,docname.text,docvalue.text) .then((value) { Navigator.push( context, MaterialPageRoute( builder: (context) => Showdata(LecturerStream: value), ), ); }); }
  • 13. Updating data Future updateData (Map<String, dynamic> ListMap, String id, String CollectionName)async{ return await FirebaseFirestore.instance .collection(CollectionName) .doc(id) .update(ListMap); }
  • 14. Future deleteData (String id, String CollectionName)async{ return await FirebaseFirestore.instance .collection(CollectionName) .doc(id) .delete(); }