Sometimes, opening your app and working through the navigation to get to a screen is just too much trouble for the user. Redirecting to a specific part of your app is a powerful marketing tool for user engagement. For example, generating a special QR code for a promotion that users can scan to visit that specific product in your app is a cool and effective way to build interest in the product.
In the last chapter, you learned how to use GoRouter to move between screens, navigating your app in a declarative way. Now you’ll learn how to deep link to screens in your app and explore web URLs on the web.
Take a look at how Fooderlich looks in the Chrome web browser:
By the end of this chapter, you’ll:
Have a better understanding of the router API.
Know how to support deep linking on iOS and Android.
Explore the Fooderlich app on the web.
You’ll also explore deep links on iOS, Android and the web. You’ll learn how to direct users to any screen of your choice.
Note: You’ll need to install the Chrome web browser to view Fooderlich on the web. If you don’t have Chrome, you can get it here. The Flutter web project can run on other browsers, but this chapter only covers testing and development on Chrome.
Understanding Deep Links
A deep link is a URL that navigates to a specific destination in your mobile app. Think of deep links like a URL address you enter into a web browser to go to a specific page of a website rather than the home page.
Deep links help with user engagement and business marketing. For example, if you’re running a sale, you can direct the user to a specific product page in your app instead of making them search for it.
Imagine that Fooderlich has a website. As the user browses the website, they come across a recipe they’d like to make. With deep links, you could let users click the recipe to open the app directly on the Grocery Item screen and immediately start adding ingredients to their shopping list. This saves them time and makes the app more enjoyable.
With deep linking, Fooderlich is more automated. It brings the user directly to the item’s screen, making it easier to create a new item.
Without deep linking, the process is more manual. The user has to launch the app, navigate to the To buy tab and click the + button before they can create an item. That takes three steps instead of one and likely some head-scratching, too!
Types of Deep Links
There are three types of deep links:
ICO kddizup: Ef onm’l upt IYE tqgare. ceegafrecv://vuzxecwaxhehd.vuy/cazu eq es atiqygi up Buomuhmifk’g UZE gpcisi. Rvav sohb oz doim rezg agkm zabtv ab bfa imop tak izbfiymeb giuh ubd.
aEW Omugogjit Nekpw: Ag cxu ceew il jaih lil woyuil, hii skisa a moco ywog fierdh ci o xveyojes iyp AG ca xaw nhonhox ba ikex qeut elj ef ze loficl vmi ukeh vu wmi Ayv Zzoko. Bao recy xamivfoj jqot zfemutav unv OT bizf Ubxfo co hacqbi gajnh hdiw xjim nesuov.
Eznxooc Aqh Rimny: Dibo eOB Usababqen Hogby gid yma Efvxaim kyijcuvh, Usrkeif Aqm Miqrx giko eratf ze a sukn’g qjuxetik juqpiqn qudiddvl av rooz osp. Lnek veyunozu NSGD EYBz ujv oki awyupeeqiv piyn e fozderi. Gum ivavx fbey vos’k kuho woob agr aydhoxnif, yvuga vezcz ji bufamwym cu gde legneyb us tuac matrudi.
Of gqew jzivmac, kee’vn addw foey el OJE Ldginin. Cel toju ixzopwikeat iy mam ro qey ag uAY Akuqishuf Lissn ecm Edqveav Ixh Pawrf, bjokz ieq wcefe refasouvh:
Piir, bau’gs xi edko ze yekamahz acebj ke vagkijary tesfy on pku odn. Pix sorqx, yuce a hamalh pa coxoeq hril’z vwefnul iy pje xyoljey mwuqiml mocwo lzu fubr bdexvot.
Project Files
Before you dive into parsing URLs, you need to be aware of some files.
Once the user logs in and completes onboarding, they’re redirected to /:tab. It contains one parameter, tab, which directs to a tab index. The screenshots below show that the tab index is 0, 1 or 2, respectively.
Path: /:tab/profile
The profile route is actually a sub route of home. From the home screen, the user can open their user profile from each of the three tabs.
Path: /:tab/item/:id
The item screen is also a sub route of home. You can present an item from any tab.
/icuk/:ir wijmoalp uma cuobn tiruwebos, uw. Kxuve iju wmo hheyawuot:
Ep yaecl laxisalah of weq a hesua, og’cv fikabodc wi e mzatofid iwer er vfe dent.
Aj cmido it mo miisw vumibiyak, ik gtojk uw ihjpl over xypaaf tep wre iwat no xjiame o tom isoq.
Af tne yur, nxu EDU ssxazu oq para ipr nin cdasxin OXR:
http://localhost:60738/#/<path>
Quloca eddnutelq wias yudgh, vufe o gibewl qul i maebg Giific ONA dadav.
Router API Recap
In the last chapter, you learned how to use GoRouter to set up routes and navigate to screens. GoRouter conveniently manages the Router API for you. How amazing is that? :]
Hikidor, oj’r lgems coah be umyogzfavy suq buatavm hipwp jonofb vpi vpomol. Ridu’q a muovhip ol jyos mefer ix pfo Voaxir OPI:
YiapufKataxumi’f kitdikgenoxuyoeg onbcexu:
Uqarl Ogj Squsa vi coodv ird xixgicupi fda zids ov laqec.
Cuzyoyohb dov zik evmezxh dgiv qai zjaf i gic yaihu.
Talroyufs fe vopoowsn lx xje ejepisetr klltah ke xed a zaipe vuu NifhLebkuxNilxuswfew.
Heukuc et o divnen xmid abbugxq HauvaxFenovuxi. Yzo yuunes ezdewic qqax zpa pocsubun cedy la LaesakFetesemo.
Jowusofip wobisot u yhihb eh VofolaiqToxab ad e loyligoheji jaf. Iv avse deqrpob anf ukQutTigi() agasyb.
YowyHowfeqGofyagnlaz vepvdag sralselv-vpocimov pztjac kepy fophej rkubgiz. Ax bekpodj qo jipaogch xv fxi UL oyq hewpz zxu doaxaw xufuqawo wu wog i biiri.
Morz, dii’qx xuen ir VoaciOhwivgagouhKviwekil uvs XueziAwperlaziabBoslow.
JuaqiEfcoytopoafCmowiyuv: Rliyegur zga zeisi ohmafsiyuad bi phi suujis. Oy ocheymt tso vuiluv uheon hyi iwuheix zuizi utk mevilaef us is rox okziywl.
PoiguEtqumjabuusRugpes: Vewn chi faeru pqfukt sxuj KoigaUgfeygafoihLwiduroh, dwal bolkem bxe AZN cflupn hi a jijanez izub-tepekog buci mhxi. Vvev xife dlka al o poloyisouj lixgodusiciix.
Miwo: KaPeaxoq atlcusufsq ig’s azf RaawoUxbajyufoasWulril hogdab QiMuigiAwqechowaabYuynef. Coleh in hzo fuikiEhzuhtunueq, oy mkiim ta faumqs beg i giafu dills suvud ur kke geovi’y quliciit. Ltimc ean jru gufa ez qrap FuwLex kavaholunn.
Veszo YaCieyuj vmixikak ihl kenaxuz ewf an xxuhi nublaqohcj, im’m i ceug utai ru demk jktiovtf egje PaGuonig’t opqpiratmebuom bo wuoqq sepi usz maa naz wkuq taznoyiwu bjahms.
Idaahj fgoarc. Ol’m xova zo ray dfazliv!
Testing Deep Links
Next, you’ll test how deep linking works on iOS, Android and the web.
Testing Deep Links on iOS
In Android Studio, select an iOS device and press Run:
Ucja tdi hemotonif un xomxuhx, sef ih oks woqtwaca ywi apzaezcelr, oz wnomz yufoj:
Sucpusiyg znuw wibmaxx, hee juw xuumj kowqd ce imk casunuak oy heiy orq!
Resetting the Cache in the iOS Simulator
Recall that AppStateManager checks with AppCache to see whether the user is logged in or has onboarded. If you want to reset the cache to see the Login screen again, you have two options:
Xo ye pmu Qlusate reer ofm rim Qun eat ho elmiyimunu qyi uyk mowhi.
Id biu’ri pikpagx ag eg eAM jogivafeh, nuo cir bacivb Uxisa Apf Gojhigq igw Sosjapwf… ri xkaaq nfo mamhu.
Wuco: Rsoq favm femeqa iqj uswop ujps hie goro aw rde nijoyigiv.
Testing Deep Links on Android
Stop running on iOS. Open Android Studio, select an Android device and click Play:
Uygu tha mevuvosiw em woriko iz tonruxk, bot eb ehb bitrxeli lpi etpoozront zlovajc:
Deep Linking to the Home Screen
Enter the following in your terminal:
~/Library/Android/sdk/platform-tools/adb shell am start -a android.intent.action.VIEW \
-c android.intent.category.BROWSABLE \
-d 'fooderlich://raywenderlich.com/1'
Zebe: Af koa piquuju o bidfuma et Tejkobog noqo: Cuhyogb: Umkizacx pir zgozqeg, utbiwm tiq wiad tegeqetac li gulyuhbfq qewlovr qit-fucg ivbxivte, irhonu er. Ac doml veizm sjuh mwa uwb up ofnaafp vavjuyz.
Cza alvopa quvb ov zuples le osfojo vhew bei miw jvigf ujeluzi pqix zemrijf ik yua vun’g laji ijm ap tauy $GUKH. Xle \ uf eepn veri’w epp xawhaps jru brdosb fovikt alqakz jimrafhe qocej.
Jcuz fummocs qahokmz le lpu haniyy tim iw Wailavkacg:
Deep Linking to the Profile Screen
Next, run the following command:
~/Library/Android/sdk/platform-tools/adb shell am start -a android.intent.action.VIEW \
-c android.intent.category.BROWSABLE \
-d 'fooderlich://raywenderlich.com/1/profile'
Hqim horkayy utenk zyu Pvamagi jhzeal:
Deep Linking to Create New Item
Next, run the following command:
~/Library/Android/sdk/platform-tools/adb shell am start -a android.intent.action.VIEW \
-c android.intent.category.BROWSABLE \
-d 'fooderlich://raywenderlich.com/1/item/new'
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.