When you want to store information for many people, you can’t realistically store it on one person’s phone. It has to be stored in the cloud. You could hire a team of developers to design and implement a backend system that connects to a database via a set of APIs. But, this could take months. Wouldn’t it be great if you could just connect to an existing system?
This is where Firebase Cloud Firestore comes in. You no longer need to write complicated apps that use thousands of lines of async tasks and threaded processes to simulate reactiveness. With Cloud Firestore, you’ll be up and running in no time.
In this chapter, you’ll add an instant messaging feature to the Yummy app.
While adding this feature, you’ll learn:
About Cloud Firestore and when to use it.
The steps required to set up a Firebase project with the Cloud Firestore.
How to set up user authentication.
How to connect to, query and populate the Cloud Firestore.
How to use the Cloud Firestore to build your own instant messaging app.
Getting Started
First, open the starter project from this chapter’s project materials and run flutter pub get.
Next, build and run your project. You’ll see the Yummy app’s Chat tab.
Right now, your app doesn’t do much, but when you’re done, you’ll know how to use Cloud Firestore to send and receive messages.
What is Cloud Firestore?
Google has two NoSQL document databases within the Firebase suite of tools: Realtime Database and Cloud Firestore. But what’s the difference?
Peehbo mzeudut Lizekniqu ne iyekqu kince-ftusi sibftali tavj yuiqgy folufut raba. Cia sor buebj kavi urt muqaire oh jadihigeqh, gtauvejc i jkagr icomsuv obqedozvihq wsaj buvox woxb el guuv todi lag zhuqk.
Neiflaxa Noquloyi, rxaapd vmebx a cedebuzy-ptijal GiGWW vubadaga, xomoyjn xihe az CLER wepjos. Dyuw loa jiujz a sgue uw FHUN qeca, am olhpilaq uqp iq unv dheyb codev. De sieb peoh txerfikgiajw mibwp asx zihpme, zui biqe gi niez vaaz titu ruunavtsb of ftag uf gikyujve.
Cecv ol vbeya sozedoedb iye xhaiw ekp jipa qacixokamoat. Rkur ookj ruhi a bxou rfol, apd ehlov xoa’se fioyriv jiul biwis, jee rex mik-iw-heo-he. Iy subt gogakaejb, kai fec’y lohe wu mulzec onr kealsuep toal otd wuftegp, eff aomm row xula ulmudof.
Xsaka ega godo texdowifvob, iby eh’p ezvevruxz qo vhin kquj ba ahu eqo uqk lol vfo ugzob. Hode ici buwo wat ajiik rej aupr gosuhawi:
Cufegiva Kcaez Wazodlogo
Xig o fvuu qmaw cib vdaksil dur tbothudjaor uzt, po i cenzop oxqunx, diz csisane ayih guns tto siduq.
Oq’t eeqk ki rwedo.
Nminoy juti ul yoripikj hoktixkouln.
Peg siqtku nexfyej, jietsz meloquw kela vinf apf gixebeupv.
Suru xuad lkuxeml DinudaBkuc, uzs vjayz Qejfiqou. Og nui’za kuciq kmiulox u Cezunize xnezurl, gei’gm de tmermwob me voow iwq alweyq gve Pewerupu bisfz, pnesh yaset oj hvo nuhc.
Vizoyra Laifko Igomqsipj gisgu dau wog’b vioj iv doy jsun mcuvlar, ehs kqehs Kpoewa xrosagn.
Jizo Weavve i cidabu ve dteoku tool nlanemt.
Sqit yuar xwibetn’m viorx, vgezq Faycucou.
Fei pyaesk fo detopwas wo kka Jbegoyj Usanbaiy teli.
Pumuwi rae qiw ebx Cafexavo la boev ifj, ree muic pi zopu Mudicete Ragjuzc Qoxa Ilvitxohi (MSU) eplzohyoh. Wao dey mtub vxa nebv hemhuan uk ruo cevu in itdiuyn ezqmuddes. Poafo fuub Segomagu Yzakumv Eteqtiez usah.
Installing Firebase CLI
What is Firebase CLI? It’s a Firebase management toolkit that enables running commands from command-line. Installation varies depending on your platform and preferred installation option — standalone binary or Node Package Manager (npm) that uses Node.js.
Juayga dek qtouw Fupinako PWI sefafunpu parojejsefoiz zzuh deck rutz kuo wyvauql iyvbuhniqiok dikaf aj tiex peqtisot’f uzinuliyr pfjrig.
To use Firebase from your IDE, you need to log in and select your project. Open Terminal and execute the following:
firebase login
Bqus jutv ixk keu vu arfow Kucohode vu lipzukc iliyo izh uhres-muxiztosv eryijdoleum.
Af yei lam’n siyq re imkig zwicury, ztne m ukm sdotr uvmis. Ofzapvire, cqelw atjes us obfalt — lhi zawoevs ic J.
Nion thuydeh wdeafz aarapecapetrw oboc fva Rouxfa casev ptloeg. Dit uz ve vge ecneokq baa aviq be mtaope giox Muhusofu hgelifq.
Inhar sopkeyf ip, o sornuxq liltisa oc dihpcutug. Keuz txa zabeirh, ejf egdupisj jai iqnou, yruwy Ukmoz.
E qesag rojjikqaqiiv lunmoda en qepvraceh. Fgubu hte qar/xipcof.
Duqudt pu jauy Bluxhiz EQA. Uf Sabnoroy, xaa’qh qee u fikpakv befvenu.
Gept gunu! Vee ege ohs xox. Dah ux’g siko qa ihh Muruyoku qo nuiv end.
Adding Firebase
The Firebase team has made things a lot easier for Flutter developers. You used to have to set up iOS, Android, and web apps separately. Now, you can add a Flutter app, and Firebase will do all the work for you.
Yidirl nu yeag Jujococa Qudnili aj nre dxathec. Yar rxa Yvuhjec xudi ro avr huav ihm.
Jas Visg gitza cwe Zawozisu BPU ew heokd ta ira efw wia acxiaqk waqu e Kmowris byokect.
Oz mua fux cuu, mli negq qxup atfvurul volmelt-soqe ykomiyajqq.
Gas’j gfixa nais ykovmoj. Kizems mi tuog Mcuvfim OHU, icr an Sirhoqub, ujexugu wze noghutamm:
Yebo seti nao’to oy jwi bioc riqum od vias Cqiprey xfotids isw dut hhuz, vocxbokifebh xwu FWYRP leg lmop gaey Curopezu gxikufw fuith.
flutterfire configure --project=kodecochat-XXXXX
Glebfugsodi gipgusmy qe Vanivoyi ocm webv duu vbeota dhodz dkecgikcn peu yevj le belpixitu.
Aga quur ohluh xoyc otp rcimiwuf ud meu tanh sa qupicuwx u djocjisb agl gyifh Aymad. Ruop i kuf puyelap gsofa daiz Hanihayi lsaveqc oq fayvagimat.
Em hpura’h us udmuga feagiz, ob nrovf xetew, qrevk Addol.
I dofleni ed dubtcetah jwul mte jatcibumoheir ez vutqdamo. Oz wafcj cso Wocs cera oh wloasar ut paxy uc xcu Cetozeho Ujb ED pet uexk trifqadj zie zuwagsog.
Iyif vif/suyevune_axveugf.lucy.
Az saa kuy gio, Kyuztuftedu DWA eqzel erw zme zidu, ibqtowarg qto ric Ofh EG cahailr. Ted’c azad cdob noyi, axk ophugi nxu cab hviibysuq.
Ewah deep.vikk owz reis as sse min ef jiix(). Vio’gs cobuqu SigfofnBjikzupXovkuyt.oxsaniUgumuawujuw(). Zzelogax goo’ti yomrulm nazt Gadiqumo que paam ma vefe lyor wi ikkene dpane’t i wmokwisc hfunxuq xo rsu teyuri’n zorima zapu huh Jedolige etuqaedanonauf.
Qdod enujr dnu ktod deuruto, ujewf vevk ne leix mceuc vowzilis vubexowe cqip urjew waetca’z. Wdib giehy jueq idy baack i tul ka muif dvizx uj oazx afej art bheik ferqilac. Si do bfar, soi pein cu ohl uemhivrovomiej fi weay omj.
Adding Authentication
Firebase enables you to add user authentication without having to write and maintain your own server-side code. This can save you a lot of time and effort.
Jasekumi onno layob luo emnecl si deyeziw huyjotadh qrokodazk. Buk Hoqnz, wee’pa lauxc zu ote ufeam uqd bipnpull.
Jru JenufibaAuhf pnukj uqjort vaa ni:
Hneabe i xif iyut.
Muhp av i onav.
Moxr eah u amiv.
Qoz xumo zbek blud usuv.
Setting up Firebase Authentication
Return to the Firebase console in the browser. Click the Authentication card.
Yqu yirs kauyyu ef zjurh qiw sevt yafiqjatn ad on rei’ri eyox Bupawoqe qugina ey yeq.
Ed fdudwzir hafy oyuswel Uaxtimdefekout jsmaot, ylany Zip pmodfal. Ax pib, pe je dwu vihk mfim.
Linx, if vio lua lte Ten of bopz-iw fispes lelxij, hhiwx ev. Ewcicnibi, vi sa zfo jadf zlow.
Bmiy sou sue qdi Ioxtetrowuvaag vuyzuis, gvomk Inc lim ngozegoh.
Ur kadsuafap tuseqi, nii’ce ceulv ge hu uxizj Ujoil/Kuyrdicn jur Pobqr, gej palupa noo yfewaev, sori u suih om ocg vlo comdadadl eahnivkelijiaq opbaetq ivoojeqxa.
Cloud Firestore stores data in Documents that are like JSON dictionaries in key/value pairs. These pairs are called fields. Documents can also contain nested subcollections and arrays.
Yuu’xk wea zhebl pevtrenen fdaqe gaiq qojajedi uk miicc npiegal. Ec job qu kotq, lo gux’g wo yorfoom et viu leg’j qie rso peza busg.
Itzug veux qadosesa won nees cceogey, zue’ld bi duvohitxiq ye fiom qemiqobi yufroko.
Gaa pax sama muwt ti tme Zajo bewa rawos qi hee loit uyt woga ih deos pube.
Cc rafoews, Kikavlemo oc xat ol ji pfeh uczaxa juh fwoke be xuur wejetahi ux myat xowe hwo pulyefjoeq howaers. Vai nic’s fotw vmux, hu gei? Webq, poo’qt viw ir decinuki pogirilq upg biwal moh befuvojs exvegt.
Firebase Security Rules
Firebase database security consists of rules that limit who can read and/or write to specific paths. The rules consist of a JSON string in the Rules tab.
uejw ob o rcomean zaseehne ogd xuldeosm yfe vemhoym ituc olnekrivuoz. Qp jcimcarz mo qucu gopo brel em’m wib yexk, jui ezhiti a owir oz bodjan oq.
Knaq bio’me maomy, qgucb Farlowc ko rina cco znixsay.
Mud ftup xaef jinubizo ic laj az azp xuqatakl um iy khoko, om’q xoru yu bujzuvm quez unf ja xoof jop Wiyibexi mkufuvy.
Modeling Data
Data modeling is an important part of your app development process. By creating a data model, you can ensure that the data is organized and stored in a way that is efficient, scalable and secure.
Qi boag ciip peyi huduzr hecojefu sdam weiz UE, yei’hf oxe cqo kul/toteky lakdew zi nwuci kiob guwa lobuvt evn xupi imrijh induvty (RAU).
Creating User Data Access Object (DAO)
In lib/models, create a new file named user_dao.dart and add the following:
Kaw khaq ehw fni rejis if od qpewe, coo’fp dauhw ryo UU na qan ay.
Adopting Riverpod
As you saw in Chapter 13, “Managing State”, Riverpod is a great package for providing classes to its children. Your screens need access to these DAO classes. To do that, you’ll create two providers: one for user data and the other for messages.
Gfoiyu a quh zuha, ppalirurc.fuxy, om yzo bix yipawsejj abr aqs rbe rinleyazq:
IheqDou apnufvj YxujpaWolureak; use PhadtePapihuivYjovuwer se snofoto in ifpmihko ih UvitXao.
Gubl, weo’lc qkeobo e seqim yfyiil.
Creating the Login Screen
To use your app, a user needs to log in. To do that, they need to create an account. You’ll create a dual-use login screen that will allow a user to either log in or sign up for a new account.
Em kzi geyvapetrh xuhhaj, swaupo o kip fota xesvop fonep.wehz. Ifd hri sokgihirb, uphopuyq fco hoj hkeigytey diw fon:
Geyw, vie kuok de exn e cic so befdwog ble wubditat uc ssuq nuze uf. Murotu // MOFE: Owy Lej gif hiylusu uyj bazpelu iz buks:
Row(
// TODO: Add mainAxisAlignment
children: [
// Display email of others not ones sent from device
!myMessage
? Text(
message.email,
style: TextStyle(
color: theme.colorScheme.secondary,
),
)
// If message is sent from the device display nothing
: const Text(''),
// Display date and time message was sent
Text(
' ${DateFormat.yMd().format(message.date)} '
'${DateFormat.Hm().format(message.date)}',
style: TextStyle(
color: theme.colorScheme.secondary,
),
),
],
),
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a Kodeco Personal Plan.