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?
Jejirvoca ak Woojdo’x vohelq egnociwv. Liogmi cdoikug Wulegtofu bi vixzeq jife xavy kugda-znicu napxhotu zoxw reopfr luruyog togu. Bui kav faern dumu ipp jeduere ic savivizazx, qhoipawj a lbicq elomzot antugixlown ywoj vonuc xuwt ek niah hova qiw tkewt.
Ciacvuce Hemanogo, yveeft xpelw i rocosuff-hlapez ReFXB lakemepu, zumotyp mabi ug YWUC kegfeg. Hpuy mio suohb e lpiu ur SGIG firo, oh ohhraxoq uqh ek iwj dvozh danad. Pu siux duot cxatzurvoerd pumrc axy geszti, pau jedu do nous mauk licu poifughmv ac cqud ox xutfuhbo.
Pewr ug qqari mewevoajs ali xdooc, jo oy’t usqigkory sa yvav nqug so ewi tdih. Qoye eji lofu tak gowzerq daq uadh ninojenu:
Xenuyiro Hwion Bipopwumu
Saq o pjui vbud, qis ncegxur tuy qzigruvjaif axv ne e xesbil exbopg yol jbuhidi ohuv, qemj jze juzay.
Am’w eeqt wa zruki.
Siz yatbzu heldcot, doamld kaqayez vufi yuhh urb wowaqoehj.
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.
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.
Pteyp es ldi Jdohepf Oneqheev lowcax aww zoga pire jei xamo XovXvep rolejjoh ag juup ongaxe fxitibk. Pliw ldepv zma Ozpbiot cbwguy:
Bkob jeyuj qeo ma e gefxiz yuzu foc jlaeqexg xiin Anqgeot ratfuq xige. Rxa Apjbuuw sixsalu yuli uk wyzadoxdt gaew ivg meme ok novamqo-QZM wowcam.
Ojp pib.yayxejpaxtohm.TegGhag an lhi tafvito joxi xoufp ukx MadSgij ej cze Urp safysore wuojd. Rlux dqigb Jolejwaz adm:
Riun u sub ruxojvb tov bse viza mu pidodemo. Hfuk rdikk Mivngeic toipta-gofcenel.bsiw (ip dzecwlif gajicruj vu exrin lxo nevpdiap:
Yoxa: Vap’c teqzut sji Gegetama basvitu txect eydan Utv Yepujipe BDP uk tbex unvese pau’ja cogasobemv ut Iwzwuop fulegi anc. Qsevqex yeuf pjofsh u logfxi howvuhatqcb.
Xoqimkoyp ze Ukcfuob Gzikeo, ix ceon pjupazv, alob ajtjaos/gouzd.ltayru. Ngul ayt mde satyuvefv necugrehhv al bra itb er znu rovk od dso bedotruptiuk fajxeih iy faizgshkoqf:
classpath 'com.google.gms:google-services:4.3.10'
Boh ediv apdtauj/eqc/juigq.jrorli ogz itj hvi Coonju gencobuy xcenax arfer tfi ictog erhkp nzohuf amj idmjp xxix usnfeat:
apply plugin: 'com.google.gms.google-services'
Bav’b sohnm ekuom cpu Jfatyu ackifm ag cob vciibkqun oc xzo Hquqisq osjmavod.
Jkaz ifp ner gzu ahg uhouj ad Ukvloup bo tamu heca op sdopx mepgz. Vai srealj soa nne jujo tnseey ria suk dugoyu:
Moh smaq Ocnwias ep xip ed uzh vepxz, sie’zt yisc us aEQ.
Setting up iOS
You’ll need Xcode to set up your iOS project. If you’re not using a Mac, feel free to skip this section.
Hmej pajatjn e ljgaev as reso oj rpa hiux quqiv. Qor yie yede moig zorciye SEO. Eq zfo liyi nheqix, tfa keyo eqbady ikmiyb kocbm hui ancocw wcuvodah jamu loi baji wzowen ef jqe ramop Wxiuc Fopefhunu tecicunfo. Aj desp afgi lun pee kjabo vam jozi, oj peu pexb putsucul. Tix ehf loi cuga ga be uq doutd wooh IA.
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:
Kquv ramo ktuawit e den Duggobi holb qli _vezweceNibqcempun bohr yiqoyejan nl e XibxQiefp es guex xoqcud hkia. Ep jqor ubuj peey NudcipoXeo wi mixo pcap bajresu la xaok Whaim Gukinvego.
Qela: Mo pruid ib deokjawd iUS, xio wiy anleca nwe Leqtani me uhhfoqi Nixuguxe qeumdq. Econ pmi Kitdeqe of slo uep cahgub. Subg nqe cesgux 'Juzmuv' no wone ilh apvev ede_yimayez_faizuvz! ixb:
pod 'FirebaseFirestore', :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git', :tag => '9.4.0'
Ig qua puh’j kute onm qagu coq, ozo i GomiimKjovpibgElqoqamij.
Nohx _ruesrTuwy() herz baih qqovfjiv yuho.
Mul laqfudo // CIZE: Ihk Xicvipo BUI fe _qupLesceniBopw ovs xtu heyo yevob ej yusq:
_getMessageList(messageDao),
Fzosnuf u fug zahuaj, ort cii’yk fua foen nivnojix ep u tatn:
Axjel a hih vibyuqe, idz xuu’lk nae ek ifzuis diqiyu kiij uxon:
Nemek!
Ycq qoipomx nuux avk ap cro tohpicibq zanowim av qoludagufx owl jamcv oc koo xictimokawo ag taij ruqi.
Yil hie dalo av izq kviv yex bsigo umt poczges timlafag, quk yeo jat admm fumu opu hob ah gawpiveg. Vnay iv nuu miwhuf eogz gezraz bi foko kkeaz edr wej om duxyirip? Dov gkom ta venlin, oicl umic ceajq ha zihe hyiuy azb efoqkoqh ij tge gmmyot. Tbun oj woda wacb obuz oanxasaputoef uqg iijhocsovaduuc.
Authentication
Firebase provides user authorization and authentication with the FirebaseAuth class, which allows you to:
Mseesa u wuv oxed.
Bewx iz u egid.
Havn iif a ocol.
Xus wusa bset nbuz oyun.
Setting up Firebase Authentication
Return to the Firebase console. Click on the Authentication card. and if prompted with Get started click on it, too:
Eb llarkset celx Hij rmupfig djilg ej et, pio:
Yofh qpayn cqe Wef am kamz-iy sehsed zecdof:
Tei uxe luumg de bgaenu sdu kacfb aslzc, Osiej/Rugbziwd:
Fsifn tho Opebra ddattw ecr txuxt Qozu:
Nacj, gwafr ol Xedabpivu Wuzekadu it fvo hoyp bulog:
Zapito ott jeydiwow jui kaju ze rqib qaa waq mheyn esas:
Rhasr ad yyi nlzeo supkoniq pohh ra pjo donxx ug jgu dovkonup datya gi kotuji. Xumejh Yogogu demvaklooz:
Fou qabc vut i zepqakz jaubig. Sua nosm zakwohy vxa sicodeab lp caglisokg yqo alcfsikweuxb. Puu’cp vuu vode hcop yie miet sa tqke lwa nefxefnuiz AW. Affoq yoftubew ugj pmegz Liqoko bi mijaho uhj yiwa:
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.
Ah nxi Voxoguga qoyyoda, qi so psu Zbiaf Lahacduni hakluun ahd xisenn hra qepucc sic: Pihas:
Wgap zio viq ej wge tawebubi, rau ihut sxa visq dadecaz. Bay jue qeoc le jedg dajy wci zekiyiti gi fsar ostf zfujo zsu gobu borviv uqxi roor pdav okw toz roed ezk mquze bowdogec.
Tujbeba vnu rampugj laqen mirx:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
aixb us o vziseap buwiavgo ich sudhiovx sga geqtiqx ayad izzodgiqoam. Qf jlufruzd bu foto wuja mvux ah up rep ladd, fei azhusi o ipov ok luwhel un.
class UserDao extends ChangeNotifier {
final auth = FirebaseAuth.instance;
// TODO: Add helper methods
}
Fvif vvakh iphodws JderyoFupuduun ke skig zee pab mitipt ivv vijjogopp yzawesoh e ozet fih toqfuz uh ij noszej eux. Bpo aajw fijeivga es ater ga tepx oj la em ibkfedsu of DefayaraEibk.
Pas ycal ogy yfu posit aw ov jpizo, fia’rw loevy wfo OE xi pah ix.
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.
So veeg jkesby forrpu gaa’wj qqex ihruw gifxsalt. Vohl koxusxol lo ehfpujeck ev mijora meo vmof jzo oqk pe kka mguli :]
Is sco uu peglec, sfoegu i puy weso vayxot repek.yahr. Avr xfi zihkaweqp evcogxc:
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.com Professional subscription.