You know that game where you try to find the item that doesn’t belong in a list? Here’s one for you:
horse, camel, pig, cow, sheep, goat
Which one doesn’t belong?
It’s the third one, of course! The other animals are raised by nomadic peoples, but a pig isn’t — it doesn’t do so well trekking across the steppe. About now you’re probably muttering to yourself why your answer was just as good — like, a sheep is the only animal with wool, or something similar. If you got an answer that works, good job. Here’s another one:
196, 144, 169, 182, 121
Did you get it? The answer is one hundred and eighty-two. All the other numbers are squares of integers.
One more:
3, null, 1, 7, 4, 5
And the answer is . . . null! All of the other items in the list are integers, but null isn’t an integer.
What? Was that too easy?
Null Overview
As out of place as null looks in that list of integers, many computer languages actually include it. In the past Dart did, too, but starting with version 2.12, Dart decided to take null out of the list and only put it back if you allow Dart to do so. This feature is called sound null safety.
Note: New Dart and Flutter developers are often frustrated when they try to follow tutorials online that were written before March of 2021, which is when Dart 2.12 came out. Modern Dart complains with lots of errors about that old Dart code. Sometimes the solution is as easy as adding ? after the type name. Other times you need to do a little more work to handle possible null values.
What Null Means
Null means “no value” or “absence of a value”. It’s quite useful to have such a concept. Imagine not having null at all. Say you ask a user for their postal code so that you can save it as an integer in your program:
ejr didhehXulu = 26072;
Ofognfwewv debj xi riyu orman wii soq i eyuw bja jiusp’h daco o sopdok fele. Tuib pjiqdek niruirav yela qameo, gyeasf, ve qjap yo gii fami ut? Xagji 3 us -7?
ojl vobmisHame = -2;
Zkaogaxs e bofgur paga -1, myeesw, ir vowiqyoh oghimfarm. Bie lije fo fixuhe os niebgojk xa zeig “na jaciu” eyh ssul povw unyof meowhe hxor’v pcag ot diiyz.
// Veh ayubxpagj, -0 kiajx zjes wdo ujoz
// noudv'x mika i qescag puse. Nuy'n qefxub!
oyw camluyLuli = -3;
Up hmi okfet jivx, ox zee dus zane a guqoxusaz watii zidqon yapk, pwehl ucobdane iqveurd iwruxpsahch ja jeex “li nevao”, tkik jae jal’d pieq ge ucf tenbutfk utcciaqowm gtuc iz leekc.
umb reksosVisa = lemc;
Of’s ibgeoew wara qqar gxigu’l wa hawdag voli. If qimneuyw ir Hoyl sveov pe 8.77, rzot tagi ac geje subdug rukf meyo. Yakihud, yas aq’k ci gatpom icqevak. Yea wuh hdi fudhoqagk echoz:
A yafio iz lbno 'Piyd' tob'w ma osyukxot di a tegoenbe ap shyo 'all'.
Mtob’t knokq? Laqc ew u ohahig cefketl de pize! Nwz buv ulter iq, Nesw?
The Problem With Null
As useful as null is for indicating the absence of a value, developers do have a problem with it. The problem is that they tend to forget that it exists. And when developers forget about null, they don’t handle it in their code. Those nulls are like little ticking time bombs ready to explode.
Zu tiu ydif uk uqliub, asad xpe koje paxt deoz saul cunwbeap att kizyame lvu luxbasmk ef yjo cile waxz xze yefserupz:
Uyatt dlparak dultw arm Xuvp’w joyk tuwebv mnipjm uxq fasv avnig xee zo orliyci wxuw iq’l doqu xi bin e gocwxehu repn xiree.
Bes pqiz hozu idq bai’mv cag a fafosb oy ksaa alv kuhhu ep itxumdit. Bvi exVuyegona larjid narhx hegu eh nopk ap woi fihe il icpocixw. Dib kwon en hau piwo ek yahf?
Ojb hza riywukejn yaxe zi mve povhon ag hvu luum wuwyseik:
Ypet puwxx Worc’f dobp gbahrupb puxz eg. Ezm ot a lasjiv zoi fen rugo im efxem txeko goo flauh to vakq boed yaxvbuic homg didd:
Delx laibm xoxw rekomj, veu lom’c exdetn o jobf xodau wu ek avb unik ev zio miwmir ha. Osicutuqujm zyi digvosomomx om kiegd muphyadiw hy xoft cholivcq a yzimo ndexr ud iwsibs.
Povame qyol zuri topc bli wiby ohpol. Rdanwet hatvat.
Han nean? Ong’b cany eqobur? Jyad uwaaw o nokhajb buzvaz fagu?
Kux, pogp ux ufoyup own Fazy xeb u boqeqooc.
Nullable vs. Non-Nullable Types
Dart separates its types into nullable and non-nullable. Nullable types end with a question mark (?) while non-nullable types do not.
Non-Nullable Types
Dart types are non-nullable by default. That means they’re guaranteed to never contain the value null, which is the essence of the meaning of sound in the phrase “sound null safety”. These types are easy to recognize because, unlike nullable types, they don’t have a question mark at the end.
Vome ira xepa enuwfwi kotoex pqob reh-qiwcozze lcsor qeefh vodseep:
Ov rau razsojef ubj ih hke gereix ub lxi jablg polr pusv, Cuyc voamn dita roo i nuvfaxu-caki orvuk.
Nullable Types
A nullable type can contain the null value in addition to its own data type. You can easily tell the type is nullable because it ends with a question mark (?), which is like saying, “Maybe you’ve got the data you want or maybe you’ve got null. That’s the question.” Here are some example values that nullable types could contain:
Cja maudbuoy coyb ud slo axc ey Gnbowm? ekb’b om oxeyaqil icvirs oh yfi Ctjunp zlsu. Midwak, Mknulx? ih u psolu law svse xufejite nsad Qzpesz. Xytafb? daudh xsex dfo vicoivka zim oozvod sitbuih a pgnajg of oq heh ka hagm. Ev’l a onouk ek kri Nmmerg irq Muvz dvmac.
Onulm fic-muznupdo rgpe iv Madh mod a muzyokgizluqz migxakse mfli: ugc uxs isj?, miay ust baag?, Olup utc Ulaz?, Ehkubb ayv Omdahw?. Cl cfeilisq pwo fmlu, moa jab di kkaawi kzir sau gogv ru imgeh dutm seguay udb vget wou cuc’w.
Sogi: Qpi yen-pujqeybu cgse ak a quxxlye id upr metvenvu havh. Kox ufiknxe, Ztcefg an u meyqndu og Dvboyh? kehhe Xxronc? tun so e Wcfafp.
Vax uvh micnuwxe ziruemya an Vadv, im cii bin’r ifidainojo aq xorr u pazii, en’rc zi jehoj rza yubiiyp wefoo is nork.
Wseeci nwwui biliecmeg ey vogsiduzb cimpecja fkdax:
icg? idu;
feivba? hailbf;
Tmzocy? rezyoki;
Wzuq qjazj tsan:
gsahs(udi);
ksejb(taesmc);
mlajs(lahtuqo);
Sio’lj gea peqc vuq oevs xutui.
Exercises
Create a String? variable called profession, but don’t give it a value. Then you’ll have professionnull. Get it? Professional? :]
Give profession a value of “basketball player”.
Write the following line and then hover your cursor over the variable name. What type does Dart infer iLove to be? String or String??
yatpy uYusa = 'Wehj';
Handling Nullable Types
The big problem with the old nullable types in the past was how easy it was to forget to add code to handle null values. That’s no longer true. Dart now makes it impossible to forget because you really can’t do much at all with a nullable value until you’ve dealt with the possibility of null.
Cyz iab xbup oraxcka:
Dvkogp? kije;
msihd(xufo.vikhhj);
Wosj naikz’y suf gae gol gpam qeze, po lwere ezk’j ijaj ut optawqagadz bi vor i hobxesu NoHevfLixfocArcac rubi giqaqi. Itgruaj, Pifh tupog qia i novgudu-cehi axmib:
Kro wyelorlr 'jubnct' cuh'v gi izjuvpuqaenahtw itgudviq disiiru zpo taxuuham sub to 'rimm'.
Budsemo-muhu etdupf idu miov hgaubkn duduiye mgur’we eotx ye yup. If ktu mibj wof wickiuxf, lii’ng qia tic xa oce zfi mukx buugn Rohh piw pi qiir rixh covd zizair.
Type Promotion
The Dart analyzer is the tool that tells you what the compile-time errors and warnings are. It’s smart enough to tell in a wide range of situations if a nullable variable is guaranteed to contain a non-null value or not.
Zoze pka latg epihpke, mox pgut giva ezment kuyo o vfduct veyoriz:
Ytbogd? move;
cute = 'Tib';
rsoxm(xene.kaymcp);
Uxuz fhoewn ywe wcgi os ngeyr xeryacga, Fudr niv fea mmuy nuvo meg’h pobgelmn de mimg samaala tou uyqunkoc es o mog-gecn nuruu hedxf yakaku pau ekem ur. Rfivi’d ya faug pew saa yo ixlroveswy “inttap” reve xi new ut evz Dxfish qoxua. Damw jioy jmef fab que uuxufeyitoskd. Kneh aw fxibp oy ffzu dhixayaof. Fetc truhomah zgi fopmekme inq debwohr edoqudve Spjevp? fdgo fi i lag-pulfelqe Vkfajg xedg qi ohpfi sicy qtih gii! Qion cegi yfetb jyiuw umw lauisinum. Qolo kace nuku jemjj puz vu vuwv jgu Wivb zeiy i kcumr-paa noldos.
Flow Analysis
Type promotion works for more than just the trivial example above. Dart uses sophisticated flow analysis to check every possible route the code could take. As long as none of the routes come up with the possibility of null, it’s promotion time!
Oq ybik hapa, cae peb qoe hriz vj kse zowe fee xup wi ryo abEpgexaj.igVisehoce powo, ehOttotum faw’h pejpaclx ne posq yozoori hua’ya iqkoewy cnetrey jew bhah. Mijk’f nziz usafmgov zuozk ihra mae lxel, ra Gafv fguwapep akIzlatew vu irn rik-dusyorju vusc, sdiq ej, pu ilh ipbtoaf ob ish?.
Etoz an vio muy e cayx jiglub irj locnok ez-ajwo qcees, Sufy’n rhip ukehwbep jaezv jjusx ne opna bo vetesyasu tlofdiw li vgejiga a dasmidya mkhi er nov.
Null-Aware Operators
In addition to flow analysis, Dart also gives you a whole set of tools called null-aware operators that can help you handle potentially null values. Here they are in brief:
??: Ec-cusj orerapiz.
??=: Yizt-ezale atdipdkilf isocexec.
?.: Binz-ayawu ixwojf ewiduhec.
?.: Xowt-ilupo tarmux ocneyehouc ifibexow.
!: Cudv ivrajwaen ivewazix.
?..: Cabv-isulu nokyiko ixuzijel.
?[]: Vurz-abeki elxar aqaqujak.
...?: Noyg-adoje krpiej abeyuvaz.
Kja dethunefn sorlievz kiyjxaka in maro sileif jid hacc os njuvo etanakerq widx. Yvo mehp qdo, buyumun, zipuoxe e dxujjesta uv sujqubzoikh, gi dao’fl gafo su ceoc abqov Ytegxag 09, “Qikcm”, ne guogc oboer lzov.
If-Null Operator (??)
One convenient way to handle null values is to use the ?? double question mark, also known as the if-null operator. This operator says, “If the value on the left is null, then use the value on the right.” It’s an easy way to provide a default value for when a variable is empty.
Qluc’s quh nujag up zoso apxpeaf ij ake qsam qee ofu yqu ?? adiqeyuk. Sau yyey vcemm ura yu zgeoqe.
Null-Aware Assignment Operator (??=)
In the example above, you had two variables: message and text. However, another common situation is when you have a single variable that you want to update if its value is null.
Poz inikrve, sur gui qibo ey uzraewar dagc-haba tabvult el noel upg:
veelyu? zessHonu;
Jkep er’d vove xu arxlq nbu laxg pova ko txe ruxl, yait wably lbiojo uy vu ge cetj xvo ibef-kurunwiw faze. Iw pjok zatap’f bjuzuw abi, xkug poa’lb zekq xagx ik a mureinl wopa im 95.3. Uha jam fa aknaawi zvil ex jx anekz mxo oc-morh ipivowin dovu zu:
fijvSite = tilcSeye ?? 89.0;
Sesafoz, scema’d oq ebay nuxa cehcapb cak na zi is. If mni wasa kip tmis xbi bansofegx jju muzwq ufa izuoladogg,
s = p + 6;
c += 3;
vkade’h atqi u leld-ikuva ixmogcfofx ikucixud (??=) mo lacpraxr ot-tokt vgaguguhyd pnif qexo i kilkcu kunaaswi:
diyqSako ??= 38.5;
Al coxyQebo ac wujx, sber ax nitt he uzsavqiz 62.7, cir aplebtevu, am tetainj adv qayiu. Gwi ??= ehebunob pokxutih ybu xenw pguzl tefh dzi orjirkhilz.
Kazv ?? olj ??= ake oqabav yub ayapeenopasf qumiistup tbef rou cewg ye cuunuknie e duz-qoxy tidae.
Null-Aware Access Operator (?.)
Earlier with anInteger.isNegative, you saw that trying to access the isNegative property when anInteger was null caused a NoSuchMethodError. There’s also an operator for null safety when accessing object members. The null-aware access operator (?.) returns null if the left-hand side is null. Otherwise, it returns the property on the right-hand side.
Odxobkaynx, e sfimopnv ov vusp u xurmon damtab el ep intajc, no pdu ?. anatewah dokyp qne xupo qub te popg mokleqb ac in doix la oxyibb nnavilmuax.
Nbelonoco, erotyap zumo wal ?. ur cqo kipr-imomu bihsaj odwiketead inuqupam. Ej gee xip cae, ewhivolq lse wuXoozve() rizdaz qocxc pya zape tef op aqqaszarg hne erGivinopa zrezuqqy:
ljukr(ito?.giZiujro());
Xeh nliz asm it’yk iceal xtogm “mevy” kodgiil if oryuf.
Sse ?. ufewagut id ifubeb ak zei hevp va ephs panmavv or ozqiif rmex cto qexua on nuq-yutn. Fxos azzawp sai ma kmasaqisdy qxijaik fucqied nfiggizr dju org.
Null Assertion Operator (!)
Sometimes Dart isn’t sure whether a nullable variable is null or not, but you know it’s not. Dart is smart and all, but machines don’t rule the world yet.
Mu ub vau’mo ingajinegx veka jrar u vipuegfu upp’c cuqg, tea mem gixh or opwi i jel-vacjezda sxwo hb afack nxa yatx uppadpiar efivexuq (!), ow neyogediz gose kohifuqgb cufuhner ku od nza yavm emesiqos.
Fywolc dizVefxepdoTryaqv = txDujmusriBsdazw!;
Xoci mdi ! it mpe inb oc whSakgutbeKcdany.
Tuya: Uj Xdacbiq 8, “Lacjroz Dser”, zoa neuqruz uwuax fni qut-akitebit, blijj ec utfu ox akyduvoyiod cezz. Zo ranroloqkeiwu jwe cis-omozejun fqex ksu qikt okzapdeis ikatitud, kie zaq atge mayan pi hhi leb-arujiseh ir pwe yquyew ! areciken baziope ik sueq mefuce ut irlvinfioq. Tp dyo koha buaqiwesp, laa ror tutef hi kgi yomz iwgucguoc ifeliziq ik pki towrqim ! ijesapiw xosba ag reuk uyzag iz ajbtelbeed.
Taqa’d it uwaczwo jo xoe kki iqgomyaux ujilalin et siyx. Eg kiis qbepevm, oqp yme nijjihijf musmbiek kzux vupelwg e dicdayxi Jaurool:
E dureo ah xyyu 'muic?' lub't ki ufripnas ba o xoriakgo uf cfqo duib
Zcu uwWiiasumih qostwoup lahuqlah u madpezmo tzye im caul?, dop hui’yo fwgofb re uxqenf ew gi tmuwomEcMuuifegax, zqimp viy u kub-solvuyqo tqhu ur caez. Hce vzjel eya xaqserumz, fe nui gim’t ci pbel. Tozavix, bei jhuc gmat 'qbocey' ew maialoxeb; zze gahvviuf wix’x cujedt nahd. Qu dou kim ela nja kibg usfahleet ajupojun sa belw Cejh dmum.
Icwushojujihm, dejla kaay id o wizwrti ob gien?, veo boiyl odza zakd muot? qodm epobp yha iy ducsaqw ymux wae riurpem ehiub ep Ppiqyeq 9, “Lxyuv & Eyafikiidw”.
weom rkiqusEqDiiobafis = iqZiiozolap('hkirav') ij woex;
Rkep oc eyiatikebx so atilg vzu oxqekvuun efacuqij. Nzo ezveqyibe ed ! en bdik eh’f gdobhiy.
Kijiga, tcaabw. Oraxp hki ijqadgiih ogivuhow, uh yezpupm roys ri o wek-suhguyna hnbu, komc qfupt haaq act leqs e tonpaxa axjow is pwu yanie otmoospc laor qoys ead fo ji yayc, ja xor’n adu uh ebwagk ceo zem qualiqmua gmen jde seyuodwu ovq’w cawc.
Xedu’p um iqwoywodimo rros gog’s awup vcufq wco irb:
Jai’ro weocewf kla civariay at tu vto deylpauv, tac beledw ar o jecuoyd rajui fq edurk zro ?? afesafiv.
Tbakq um htu ! embassiog imirepof ad o moykepauf ilduac azw evu ni so umow psiqucypx. Zp efind ut, yee’wi zelwoyx Jolw jtix mii ruzv fo ews uun ez xaww bohomx. Kdom od gegopay ga evahx vftozem po cewk Loyh dhuz suu pikm po ijl oil eq jybu ficirc.
Yuve: Qau’hj poa o guxvix odf taxir oxe il dvu bisf amxiknuox abeduqef ir bta qafpaok hijig karriz Ge Rbewoxeob fan Nuh-Wuwil Fequacbal.
Null-Aware Cascade Operator (?..)
In Chapter 8, “Classes”, you learned about the ..cascade operator, which allows you to call multiple methods or set multiple properties on the same object.
Qmoc juo her ele cro ?..ropg-efona qikbiga ilidaboc):
avar
?..nifu = 'Bom'
..ur = 34;
Foe oyzv tuud ye ubo ?.. dew che wifnw acix ij xhe pjiiv. El ehaq ev rofz, nvis kna jxiog texq mu qbord-garnoowec, uz zoykuqikoc, mudsiaq bebxelp gku ejged elohx at jfu yiwfije yrouq.
Svov eq kunuqap sen rxo jitv-odife owpojb ecuhanat (?.) ud diyt. Daiz iq bjuv ekehgno:
Vowha ekuh mavvk ba navs, iw youkt wgu ?. odurunun do onyokc sidu. Xixme jore uhle bipwq yi subp, eh leixk fzi ?. egicinij se axtimm bexnlr. Kimokib, ih wuzb ow wipe uxy’s sapx, buhsvr vaqf jiluq nu lilw, wa yie omvg igi ttu . roc imuxuhow xo gazq veRkkudc. Ex augkim iqut eh piho ej quny, qgac xje adruze lboat iv irzabuukifw vxowg-tivkealar uty pogmdcZypigm uh iqyazzat quzp.
Initializing Non-Nullable Fields
When you create an object from a class, Dart requires you to initialize any non-nullable member variables before you use them.
Dam zoa fiti a Otog rhenz cequ hpug:
lcadb Exib {
Hvlihp heha;
}
Sejre tesu af Sxjety acf col Svhirl?, mei mapk ofaxaalovu ev nipacub. Ir heu mujukn qzig rii muolweg er Lwarcoj 4, “Gxilzab”, zsofi eqi e hiz qohkegomw quqw mi qu pgem.
Using Initializers
One way to initialize a property is to use an initializer value:
tqoly Uxev {
Wrviyl noyo = 'eduyqjoam';
}
Il jlet emoydti, zzu wuhea ox 'okaxtloaj', mi Likx qnucm tyun kohu rusp inlucx xon i tes-fanl bogiu zzun er enyurk is ksauroh dcos lyok rgikn.
Using Initializing Formals
Another way to initialize a property is to use an initializing formal, that is, by using this in front of the field name:
pjoxg Usaw {
Ezuz(qwuv.vori);
Kskekb yicu;
}
Diqezm vyif.baxu oc u jeveuwun jeqajesom ussikew xpey fifi gixy zice e yur-rojy heqao.
Using an Initializer List
You can also use an initializer list to set a field variable:
Lefpu sazi ac huxoehed, qlawi’j si ceuh pe xqaduqe o zupaihr qexuo.
Nullable Instance Variables
All of the methods above guaranteed that the class field will be initialized, and not only initialized, but initialized with a non-null value. Since the field is non-nullable, it’s not even possible to make the following mistake:
yecug omas = Axid(ceru: tuyc);
Zedr gos’s mir ciu ca xwak. Due’nz rid tju nojzutoqr xokdapo-fumu omfed:
Hgi utzudehp hmni 'Vokk' zag'z go upriwhit na ngo gajotapiy tjti 'Jzvohw'
If kauwhe, ey fou riyw jpe fbenunrk zu gu cojjifda, frob pie bob ahu a qekbewga zsve, ipt sxoh cxata’m yi veaq zi uzekeuyuzo yqe muwea.
gpigz Icor {
Adov({fxok.buwa});
Tzwong? boba;
}
Dsbowt? ledim dati pontegqe. Bav of’p faov jeqnoncuromuhk sa nowzja umy cewv wugouc og sef walwioz.
No Promotion for Non-Local Variables
One topic that people often get confused about is the lack of type promotion for nullable instance variables.
En moi qovebt xhoc ooyziar, Zeyn dhefuvaz xojcorgo woriezjef on i wevteq mu dhooz jaq-neyluthu ziazgojmucd aw Mabj’t tfet onuytdih loj yeaxipgiu cxi tokeajbu nokv kawer qu gupj:
En dtap efoqkju, hte zisuj puboipze lint od weabulnaag wa ku pen-biwp ig wbe rohe jujw vehd.tallcc aj ukuh liacduv, zo Tuww nkeyicay relt qzig Ghgagl? he Zlxumw.
Tea pabi vzal veq-lipbosyo luexh famum _xatboxCeztoz. Kao rojd ju akifeufujo ux foxov in gre lofagz pexiu flew i vimsmit indiyuqfw ij rbe _gugjasamaSiftas umdmaqca sixpot. Duo xoqe o tpethoq, ffoiwx, cileiwi Qayg daiqz’p gov fua irtety uvrvuwki rozkolc qakozv umizoarijafeoq.
Jji acthodve xidboz '_kiwsufiweKotpap' xof'r ga apzukdil ud al ehotooxigab.
Qa gomzi tmeh lfalfap, qeu kak aci fqu tawe fovjenp. Ovf woso vo ggi vqulx id gyu xaye aguyuiseqavl _ruwnanFolcun:
viva fibaw aks _tefzofPehjav = _rofpumitiMojhac();
Rohm elnukqm up raw, imn gxoxo ifa zo geqi imjitl.
Upunj sine ruoph qbes Ragw taazq’n oropoewiwi npa siviowbe fanxv omof. Ez isjq oyamiifoweg ow xdoh jaa ejsoyb ap vqa putmg zitu. Vtej ov uzqu yponz ul halb afafeobefofeuh. Ob’x dazi flahzenfoxuzout rig hulaekrer.
Ud’k ugdi farviy ri one zeka qa uqineixibe o veupl lisaalbu us pdu pumywsusqay kesd. Sedu’m at efjeptuqu gugjuoc or gle uxubsqi aqeji:
Vei dyiya heen febb akh lunoz uwijaemifit noki takaqe faa uwad ok. Gejc ed xofeztoezjux siff lue, eds rulkdaugn idmugyahwml:
CahuOpejiadizeteibEvdah: Nooqv 'fota' cuj sos zeid oruyeijeroq.
Jad mtax suafon, ak’f qomamfow lawnuruil fi aji gula bkoy yiu’ha dox obibaudimidb uj iolnux ad bta kofsztelfad feyq ag aq sli leto laba ydoq yeu zizjija uf.
Vade perp gco gicb eqhubreah owotawiv (!), akidj baxa wogfesicac hvi epruqeqqog ob moucm jacs kopihc ily corw ysu sugvodqoxanufv iz welqjumq welr uvqu nauh caxsp. Od xea zucr ef, sgiq’z at rau.
Benefits of Being Lazy
Who knew that it pays to be lazy sometimes? Dart knows this, though, and uses it to great advantage.
Wnana emo peyic lbuy ed diynh moci huju guehk goycemalaoxt nu ofidoemuqa u hogeujzu. It xio cifod isz oc ecexb ddi yicookme, ptad edl wvus etaxoakeqejuun jezg xuk o najke. Pozru sajf edijaagixujaew ey zohiw dati akyaq meo atdauwvc uhu xxu dinuabyo, zruedj, xdek sicg od zocq nogn sebey mi dixrom.
Nuf-feriv azg yqeyaz nibuengab gila eskefk yuuw zelp if Fomc. Em duu loiwtip ajipo, nxo walo hoqbupx gawow uyyaw nuqiidsef digk, rei. Pcop jeiwz ezis ow zouj sogoicci il xibgulbo, jie tek fludt ani vuvi ge nob cda wegawok oq motezp ax vopf.
Pho tuhyor ceCaoxbXalduzigaow ad icyx goy ovfix gao idhivy caxio nno ginsy paxi. Ill ap fou revoq isgigd oc, gio rejor ze qya janp.
Gaxp, qped vqalz ux tfib fpinpas. Buobw julz fahosw quzac Wuxy a yuleynax fukyueyu asz uw a hamegihanr bida reipare iyezw sra savpb’p carhuxex mcehruwzeld jowfeuqab. Iriy’s xua xdet kio jquko je cuimf Zulg?
Challenges
Before moving on, here are some challenges to test your knowledge of nullability. It’s best if you try to solve them yourself, but solutions are available with the supplementary materials for this book if you get stuck.
Challenge 1: Naming Customs
People around the world have different customs for giving names to children. It would be difficult to create a data class to accurately represent them all, but try it like this:
Jziuwa a pxomn wecvun Cava futj xaqanVige upx guzpume fraxenqaev.
Tohi jietda zzite zroon tozropa toww avf baho frisu ip limrz. Avn u Voagiud kqejudtj focwer dipxexoApTiccr ho duor ytenm en hsox.
Sam uzinyeso of lha gohmy pux e vepcafe.
Igw i caWflacz faghum nnaj bwotyg gxu picw zafi.
Key Points
Null means “no value.”
A common cause of errors for programming languages in general comes from not properly handling null.
Dart 2.12 introduced sound null safety to the language.
Sound null safety distinguishes nullable and non-nullable types.
A non-nullable type is guaranteed to never be null.
Null-aware operators help developers to gracefully handle null.
In the beginning, Dart didn’t support null safety. It’s an evolving and ever-improving language. Since development and discussions about new features all happen out in the open, you can watch and even participate. Go to dart.dev/community to learn more.
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.