Lecture 4 - Mobile Programming 2
Lecture 4 - Mobile Programming 2
Programming using
Flutter
Dr.Taraggy
Ghanim
Firebase as a
backend
Firebase – sign in using the google
website account
Create a
project
Choose any project-name and press
continue
No need to enable Google
Analytics
You can disable Google
Analytics
Now press create
project
Wait till the project is
created
Press
continue
Build →real-time
database
Rest create
database
Choose any location, it doesn't
matter
Start in test
mode
Finally database
exists
Installing flutter http
package
Here is the http
package
The needed command for
installation
Write the installation command in the
terminal
Now we are ready to import the
package
Firebase
commands
Get: get data from firebase
Map represents
headers
( meta data)
map header ID
to its value
Body represents
data to
outgoing
requests
Format of
url
Unique ID is generated by
default
If any errors
exist….
Post return future response ( object eventually give
access to other data)
Wait for response first then
proceed
Response has status code
and body
Success code
200,201
Failure code
4xx, 5xx
We can print code
and body
Adding new
item
Get- sending data from firebase
to flutter
Decoding response
Deleting data from
firebase
Deleting item need specific
item id
If something wrong happens…. Undo removing
item locally
Proble
m
Solution==River
pod
How Riverpod
Works?
Create
Provider
Create folder providers--
meal_provider.dart
Import packages, create provider object to return
dummymeals
Use
Provider
Import packages in
tabs.dart
Change Stateful widget to Consumer Stateful Widget,
change state to consumer state
Import riverpod in
main
Add provider scope to
runApp
https://riverpod.dev/docs/concepts/reading#using-
refwatch-to-ob serve-a-provider
https://docs.flutter.dev/cookbook/design/snackbars
Ref. read() connect the meal details to the
provider