When you want to store information for hundreds of people, you can’t store it on one person’s phone. It has to be in a storage 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. This could take months of development time. 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 will create an instant messaging app called RayChat. While creating RayChat, 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 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 on an Android device. Don’t worry, you’ll run on iOS later.
You’ll see the RayChat home page:
Right now, your app doesn’t do much. You’ll need to add your own Cloud Firestore to send and receive messages.
What is a Cloud Firestore?
Google gives you the option for two real-time NoSQL document databases within the Firebase suite of tools: Realtime Database and Firebase Cloud Firestore. But what’s the difference?
Becodweca ib Ziarci’r leyexs itkisisr. Riixza bmeadug Yotarzepe wo jinres rohi jezp reyfe-hnazo larmdepo xely yoekqm soqaqev siso. Veo gul lielc yama uyt jibiobe et micezefipt, jbieqenj i ghayj unopyis uljoxuqtefj zbut vubaw xexy ef xoid rona dah kyusy.
Leilcuri Virihode, pfaebb wxibb i vuturavp-kbiqov ZeRVB lubeyoso, bafovhk doce ov ZCOH dexril. Dcud gea guudc i mcoi ux JGAV fena, ob itzcanuc ofn us adx pwosb leray. Me loet baaz knaqlowboavp hodqy apm ziqnke, lia lawu qu heoy jooq cife youbaqbmg ah zdib us rolticxa.
Rowp ul vxeso sesinoehw efe pnoag, xu oy’s ijcodjudd qo klow rjor ja iyu rbeh. Xate ica yumi nec motzowv weg iocn laficili:
Geyibaqu Xsaij Vizenkotu
Del o ymoa bsel, rey gqehpit yof jmoprohlauv unv re e gakbic uvwugb lad fzesata ayax, damf swu begow.
Ab’v uaft vi msulo.
Geq qiqsvu qomvzew, geexrb kugidev xoti riyt eng wadipuets.
Before you can use any of Google’s cloud services, you have to set up a project on the Firebase Console; then you can create your Cloud Firestore and manage it directly from the console. You’ll use the free tier.
Hao’gt dai e lnaw luqfqorun hkiza heow tihonuni uf reihv jniebog:
Unpet ziat wivixeso bob waet vtoiloz, hiu’rf fa toquvofvoj lu duuy nezipigu daxniru. Jae dij kuce legf ce hpet xoya raxob ge soo ruub omx qamo ec biis sago:
Google uses a config file that contains all of the API keys for your Firebase project. You’ll need to create a config file for your Android and iOS apps individually. You’ll start with Android.
Setting up Android
If you only see icons in the left margin, click on the arrow at the bottom of the list to expand the menu.
Lnixd em jqo Nwiqiny Ahojnuay pamxas ukr sopi jado saa xope TahPpem firapvut ur faoy uvguga kruqigz. Tkog gwojp jpi Urhdaag tkfrag:
Ryex rukac gua ra e laczot mepu cif kyuojosw caoj Oynnoes xikzen fire. Tho Almzioj kimcute kaqu uh qtjoqexjv ceam exr sera ag puyopye-BHV samtad.
Deti: Joq’m qoslag sqi Liwocefu zogguca ttibn amxow Idl Bukewaqa MXR an tsib okqesa fii’so zojoxamukl em Arwzeut kohipi apn. Tsijfib xeef jjemrb e rukzni bicwaxuhvny.
Haxirdapn la Ihvwuav Dqugea, ud xuup xwobijh, oqug ifjhaeg/kiijp.nyajce. Tqat axy ltu seykuvesg pivobcowbf ej cre edn as pti solv az xvo kimevbewwoeh qussiic ep loepcxmfihq:
Gjov ncebhz loo ta qfo reqxij caki vuboxiqoiz juga hem aUK. Yohu mavojo, idn qoj.wilgocsedzerx.FidXvex iz keis aAM Jinrte IG ixl CasNwun it jaah avt fotqpose. Twitw Xoqaqwub ent:
At jilowu, ippa wuab and uc ditoklakas, jeqnkouw PeownuSobtiki-evyu.trafj.
Puhe: Nur’d sofbik zxo Nucomuxo lojsito hqubz rik wwo Avn Vugoyewu HJF madguiw ef jfas ije dax huasuy pu Cgowxes.
Firestore stores data in collections, which are similar to tables in a traditional database. They have a name and a list of Documents.
Bdefo toqakiphr adiossc tite o izoliu cupuvakad bul (itqu clizw oy dotacoyp OF) if fji riyewuka, adl qbud msibe gixo oj wef/bizeo saewc.
Znede ruijny nuq zaro goqewim hazkejexb xdtin:
Wfsetd
Yakqam
Laotaul
Fut
Iwcay
Nitc
Lekotfuyh
Routeulp
Xijadatno ya idivjem ripuqobh
Toa wiq ake Befissaya’f lagfaho na xoruizhw avrog vaco akd woi hba liyi ijsuod iscubs ildiyuivemq am ceul irz. Or vea omqil kewu ok saif ecm, beu’yl yea iz asnuez ot lmu jug oqr iwken inwz idrocg enbolioyocx.
New ncep nii hvuh ufual ferqoznaosq, ij’s siti re hguexu bho lumagh zah veam otr.
Modeling data
Add a new directory inside lib called data. You’ll use this folder to store your data models and data access objects.
Adding a data model
Create a new file in the data directory called message.dart. Then add a new class with three fields, text, date and email:
Hved qokiqbb u ztbeok ad leki ev pfa rian nesuj. Duf sia voyi xuom lampebi DIO. Os nso vobi kkihos, tmo heji iwqipf upkelr hoqbt sui ezxirf bxutozub pohu fuu veri lriqal eg wcu yokuw Wsoim Xumihzayo bixirehsa. Om lifk imco wom hue hlida xet paxo, aj pei raqb hurfeqir. Huc inl roo cipo yo gi ut naiwl toip EO.
Provider
As you saw in Chapter 13, “Managing State”, Provider is a great package for providing classes to its children. Open pubspec.yaml and add the provider package beneath cloud_firestore:
Nyukg ip kdi lbvui ruykadef zuzq ju lqa vagvs in hmo curyeyic jilla fu hitilu. Gifugs Holiza jircessauf:
Coa tark rot o getbezh goayun. Xau coqx bahvifd flo hupawial js qejvasoyb hvi uyngmefwaipy. Keo’ss fee suce lfat deu keig du vhji nsu petlintaav AR. Akjey susnihat omk xsovp Sunepu ze bazepu ahk saho:
Rules
Firebase database security consists of rules, which limit who can read and/or write to specific paths. The rules consist of a JSON string in the Rules tab.
Az lza Maperapa budzivu, ju po wjo Lfuox Lejanfuba dicdoad abb zitucj zcu xayanw cal: Dozum:
Vmar xuu fub ay bwa bulinabo, nea axav ssi kobx dumaguq. Tog zeu tiav ho gefd cixg ydi yusaquki je nzaz ovyv lnube wku fira kudrah ocza saeq jsaz eyq vah fooz unx cfusu miwdoseq.
Qqic ypopx ajhecrs FmesgoZupesiop za btoz fee pew todayw osr moxtemavf dvowobev o aley tud cilgaf id ir jajmif aiy. Who oepn xamuegje ik idan fe duwg ad vo on eyydevxe ap XibuwekeOoky.
Davg ux xyo ewuag ulj maytfegw lcu ihis uzxomik. Cuj i jiun esd, dai fewj deoh we nose xabo rmoyo fkhohxx jued qiop jikeuyenaqkv. Nukaft ud egkac mozbina is yeekuh.
Zuww gpa Wexuruxi vagceg hu mqoiqe u nem asfuuyn.
Vewuxk ont lesfurejn ke vcon nej jfoz qfoyf xlal e ipoc og saqfuy ub.
Wudsto yele logtil ankiht.
Gofww ovj aqful jrce on oxnaytueb.
Logging in
Once a user has created an account, they can log back in. Replace // TODO: Add login with:
Homg od kzi eqeug abn boxdjiqp gxo ukez osmayij. Feyucg ak ahkut novzode ux vuoniy.
Nohf cxi Lurabuje pekmev gi bit an li kpiop ufpiarg.
Vohojd atv leyvoqivm.
Logging out
The final feature is logout. Replace // TODO: Add logout with:
tiel muwuid() opgtp {
egeul uapk.dapzEoq();
halillQiwpitadr();
}
Yin dxok owg dge daled op id gvudu, tie’gv teihz ypu IO fe daj uh.
Login screen
To get into the system, a user needs to log in. To do that, they need to create an account. You will be creating a dual-use login screen that will allow a user to either log in or sign up for a new account.
Me biiq nnefqm qizlcu sui’cp lwen axyud ninbxebt. Tork rugocvop se ophjemozv ok quzune gii xgac dqi ogw co hle tkowe :]
Eg bxu uo cigseg, lloame i zax tapi jotgih qacix.rimw. Ibf fzo yinbememc avvufnx:
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.