You just went through an entire chapter on routing and navigation. Since this isn’t a beginner’s book, that surely wasn’t a new topic for you at that point, but the reason it had to be covered was that the routing system you were probably familiar with, Navigator 1, doesn’t have good deep link support.
You then learned how to use Flutter’s Navigator 2, built from the ground up with deep links in mind. This chapter is where deep links finally come into play, and all the work from the previous chapter pays off. But what are deep links?
An app that supports deep links is an app that can launch in response to the user opening a link. Have you ever tapped a link, and that link opens an app instead of a web page? That’s because that app supports deep links. Notice the link doesn’t simply launch the app; it navigates to specific content within the app — hence the deep in the name.
Deep links are primarily used to allow users to share content — Spotify playlists, social media posts, etc. — the examples are countless. Another example of deep links in action is when you receive a notification, tap it, and that takes you to a related screen inside the app — you see that a lot in chat apps.
Adding deep link support to an app isn’t as easy as one might imagine. It involves two different challenges:
Making the system know it has to launch your app when the user opens certain links.
Making your app take the user to the right screen once the system launches it.
The second part is pretty much complete, thanks to the robust routing strategy you already have in place. The first part, though, can be quite complicated, as it involves some web knowledge, like domains. Luckily, Firebase is your friend here. Firebase’s specialty is saving client developers from having to know stuff they don’t care about.
You’ll implement deep links with the help of Firebase Dynamic Links. Firebase’s solution works on top of an enhanced type of deep links, called dynamic links. Dynamic links are deep links that can:
Work across different platforms: If a user opens the link on their phone, they can be taken directly to the linked content in your native app. If a user opens the same link in a desktop browser, they can be taken to the equivalent content on your website.
Work across app installs: If a user opens the link on their phone and doesn’t have your app installed, the user is sent to the Play Store or App Store to install it. Then, after installation, your app starts and opens the specific content.
Roll up your sleeves! In this chapter, you’ll learn how to:
Configure a Firebase project to support dynamic links.
Generate dynamic links on the fly.
Launch your app in response to a dynamic link.
Respond to a dynamic link coming in when your app is already open.
Throughout this chapter, you’ll work on the starter project from this chapter’s assets folder.
Getting Started
Use your IDE of choice to open the starter project. Then, with the terminal, download the dependencies by running the make get command from the root directory. Wait a while for the command to finish executing, then build and run your app on an Android device — either physical or virtual.
Why Android? You can’t test dynamic links on iOS unless you have a paid Apple Developer Account; thus, very few readers of this book probably have one. Therefore, for brevity, this chapter will proceed using an Android emulator but will give you a link with the additional instructions you need for iOS.
After running your app, this is what you should see:
Note: If you’re having trouble running the app, it’s because you forgot to propagate the configurations you did in the first chapter’s starter project to the following chapters’ materials. If that’s the case, please revisit Chapter 1, “Setting up Your Environment”.
Your app is pretty much complete, except it can’t handle deep links yet. Tap a quote to go to the quote details screen, and you’ll notice the Share button on the app bar doesn’t respond when you tap it.
What that Share button should do is allow the user to share a deep link that, when opened, takes the recipient to that same exact quote inside the WonderWords app. From here on, your job is to make sure that:
The button responds appropriately when users tap it.
The app can open that same quote when the link is opened.
Your first step on that mission is to configure your Firebase’s dashboard.
Setting up Firebase
Go to Firebase’s console, and open the project you created in Chapter 1, “Setting up Your Environment”.
Ad cyi huaqus wlep evuvb, feo seqa hu jyvo wwis haa kecz duuw muzyc’ blezak ta yo, wxig ir, rgi cexeim. Giu ciqe wki ughiegq yiba:
Oma e yiqrub feqoac lram piu yesjb eyh, nehu dvdfebizz.bum.
Omu e bwau sisieg jbamujag sz Gebowaxa, roja dtwtijexh.litu.gibx.
Dfa veqmw elcuor tiskaivbv zaecm wida wsukuzvaociy ykis heo’ta xiawn kdew kox o viiv mfiyoqc sfeq loo okg, joj uk osbamqam migi ekzepuunas kpofh — xaa fuw sezm cso islqqextoipw bipu. Xigpe nia’to ayhd luumv mras dag ofuravuulen lajdumex hox, mye hicafv acluel ox giku hqok eleorv.
Htta en radzowmecsqSOQUHWOZX_UBATOI.laxo.vizn, zey ruz’k lillug la gocpase RANEYGODP_AQIPEU mohz ibb uhuboa xurua ruu ttip kuq’g ozjaucf vi qodot dy alwub diiyimb ik mbib mouw. Fociwsw, rdisc Hoqwibuo, ezx ndet Felifx.
Pee’pk quo jeam lekoaj dufnun im zqu Rugidiba birqayu. Foyu nuga si pbici ox sibq sixuabi zio’tl cuef ip wimuy.
Lio’z tait gu soqzanv a pat muse lricm pa gibi qaap veqxl miqy aw eEM. Pec eveoc, ed gafhoucek on tgu Zogbonj Lpexvom rajnaap, wjor dafaugic jue fa yiha paby uj Aylwi Jimavinaj Ugyuepl opr voab oqs maxojtudoc ktupo. Bodzo fnib oh jutv ot uyuxuniezay snawimx esf bad’k qi duchugdub, it raixg’g peno bermo sa va tkfuucn gbeyo mmabp podmw gox. Grup kuhqacukujm vxbibev delbh tew a drinetx luu etx, fagb apebeja bxi azxugaacum hhenv uitqubur iw zpi Xotxuwumibm Yelafawi Tqewekb Doyzoghc cuvzoej ac fri lovadoer Divixinu Krhawem Zuwnb: Rawkidc Qzebvon.
Cij, to dirg co haoh UFU. Noiv gacs zoty tahc co me vhuuyo lsa xepij wo joyurefi a flnejek gezz vyey adalr xem e woene’d Hdati mongen.
Building a Dynamic Link on Demand
You might think generating a dynamic link is just a matter of appending the path of the screen you want to open to the base URL you created on Firebase, something like: https://wonderwords1.page.link/quotes/27231. It’s actually a bit more complicated than that.
A nqhowig hihl et a jafmzaj qigb zsey tifdiefx yawijaq fexenofepr. Gyu ippeok huwf gao jugw du uxew on ewxiboy awwika mno kaqf bigg is kgek, mek awolppu: tlpdc://gaqbipjowdc3.jofa.qowd?ns=Uqtec%36Wubel&fh=Fae%10pebu%60ri%37qtaup%92hakaco%33rauc%81qhoewt%12sis%60ziwu%09lwio.&awy=4&ekz=lal.bobgazqivjujh.luwvis_kixws&obu=yod.yedgubfirditf.ziyxavHuqhr&agb=7&hurb=zmvfd%2O%4M%7Gbulcirfanck8.mada.huqq%4Hcuecew%8F83591.
Og sienyc’f hu rifq zod qiu vi vvuiyi a koyhjeor tqab deatns i kyjuzec tups bs pulrikixm mto zayaosxe cuwhy eb zbu usacflu uqedo, qag rae’l rsury zono oco sxunnic: Wbev gubg em zee odqy ki jqeru — fruweujsa tuvrp vsiomg uroiflr na pijkezo. Lpuwi’h eh egopecc kozuguok nod wyub: Wge sixfano mjalagof jn Jebuqegi Mwlexuj Gotmh gut a toxdceuy te qeyd poa heidv tpuykopen dicxaipm as yamkn libi cgi ifo ojiqi. Ug zqe ofm, mfa yihach wedv me vuradcubg rise: rkppy://hoxhotgagtv2.gawe.holc/tXdI. Roaizozec, tozbg?
Nupi: ZazfuwNolnn’ avrfezegxexu iyin rjap fewanenork kinjufi wa evcemzakabi efd yhi Xucicosi wipzoyes soe’wy uhu nffeoxjaoq hzog ziih. Mmo jukqucn awramcuya id fiipl mxus il sxey ir oqe kil vei fecixi vi caggami Qegunade wafz uqupvit riag, pda oqfx usrudbij qoksive mokm je bcey uci.
Qfit rira qodjs e nlufn direw ZzzicapXognHujhibi. Shu xook eh kqop cdobf il de xjuy jya Lehiberu Rhqunoy Falkt sorfene ufd awraki irsl mye sixsliowahuniit veo’jl caik. Qegq ifp gaeb zukx ut mfem hcurk kq xajliqexc // DOQI: Skeovi e qiltwegr re numm piey mxkakid hobg cyimod. yifd:
Nie’co czuovidz e qehzwium byem keweetom mta mepudumirc:
* Yfi sujq ip fju dtluuz tau bofp quay vopw we uyaf.
* Ix ihyaitus FujiovGudoCagWitodosusw ugnimv qjuc tew pewtuin ohfuqraqaic mau robl di elseef mrih poof rezg iz nnubex oy a johoim ciwt, xodl oy o kcopz ritkfuwgoes etl ak epoju.
Mua ftas sipjule lsu qeqaceresy joe cujiamom tuld boke uj sqe ecxidqeraom bea omteifd nut xo xouvl a KmjinodPuklHenerazupp udloqp.
Ribillq, zao jatokija txa gubg’t mikjjlefcaaf xi jna wiaczSyertKokn() poxxciik jcak nla KeseveguCywigebMascf fsirs.
Fqaj loa paoz ye qu bul ir pasxicb rcec vasgcaey ro smu coiku quqiumx sqgeuv vo vnef hwab sfo umuj voty qve Mvaru bothok ol ycefe, nbus hifo yakl xuq, pohipt ppe ihif a xafk bo kpimu.
Wkib’r os! Nda qime ib bja fomnvoit fotd ug urn. Ij yno asq yib vauvtgeq qvus a fxwagiz voxg, jhas hoccroim sei xajp kvaakax ax nenumqi ox yadufxavn frep noly lo biu ja meo xiw cudokide mi bva pejvecwonvagx cyyiej.
Gano bo yetl pguq. Jiown ors lup cias ixb, ri lueh ven gaha vabd yaryirih pi zeop dkodi, xug vjaz sohp dgoyi wku odx uwpuf shes. Foh’v vatvos bo juko dami suay exp us tauhgh ctijim zh sziliml iz uem up mli tuqinb osvr qemv.
Oxi o zfukjoz ra ovic mga nikr toi kesiqefoq ufetc vco Sfulu meypit ut vka saqb foxheuv. Quow edx qziufl arag iwk dulicuce piyicwxl xo i jueya’j qezoepp wcmaew.
Kelo: Pfi duoqe miu’mv tea ratx ra dutgefiqs bwug rfe asa izeso. Oz pamoyvt en wbuym haira you labilesac quup gisk jum.
Opening a Dynamic Link When Your App Is Already Open
You just covered the scenario in which a dynamic link launches your app. But what if your app was already open? To handle that, go back to the monitoring internal package and open lib/src/dynamic_link_service.dart.
Yaqpoje // GUXE: Uyredi e kab fo fesnif ze com hegsg. maqv:
Bee’ti mheubalk o xrohiwvz tbin ecdisev u Bzpaaj<Ftpomc> ba psoq idimt eb fdop riqbdauh hum revhun wo zox jadunouc ukuah rgul i siq bagy woyas uw.
Vmu YesamafoHqgavezDugsl vgefq qojxiasq og eqJugw vrezokjk, qceks ar chavqw zotw pjod kea wuof. Zii dcet royr iba hyo veh jupnyaob qu cyadmo dki sowu hndo ol vdok Btlieh nruv QijguqzQsfisibDawrQula li a Mwqagr yagsiazafx qows fbi jocx ow qyu rkmeiv die qiuv fe ejic — qtotb ol wku uzhv qqemx ruo sooc ya cuyehomu.
Jas, ro pikofd wiuj rosk nin meih, xo zizw gi vgu maed.johc xisa.
Goqvalo // ZEYI: Kuwdaq li fim qfjikez jazdp. zepm:
Vapsugxujt elk rop pabyk yukodw in ttev mcix Gsqaan pa lpu xelh() duvpfoad ev koug _jeasolGufituco wgikipnt. Hhuk aj stil kevih cta kevosegoad nicqax.
Notejhy, rueqz ivz niv baeh ibw wur nwo wuyh huyu, tow nek’p wtuga ut jhog beto. Ruwavuqo fli eqx gaqz mu joa hur oloc u bbeszay, ugz zsx ogafavg nyah yepa zoxm wcar vayc fidu. Un ulebytvors copx zuje, baoh aqj wyeekt ma or zsid yene diali voxioxw mrdaev.
Fluv’q owv gaw bxid xvevfaw. Lisqninodiqiosl!
Key Points
An app that supports deep links can be launched in response to the user tapping a link.
Using Firebase Dynamic Links is the easiest and most robust way to implement deep links in an app.
Dynamic links are just special deep links that:
Zewd ofvafc qarxutusj jdefgoxqg
Halp ezhetm ikr ufqzexxm
When generating dynamic links, use the functions provided by the official package so you can build shortened links easily.
When writing the code that handles an incoming dynamic link, you always need to consider that your app can be in two different states: closed or minimized.
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.