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, then letting the user scan the QR code 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 Navigator 2.0 to move between screens with a router widget, navigating your app in a declarative way. Now, you’ll learn to use more features of Navigator 2.0. Specifically, you’ll learn how to deep link to screens in your app and handle web URLs on the web.
For example, here’s how Fooderlich will look in the Chrome web browser:
By the end of this chapter, you’ll know how to:
Parse URL strings and query parameters.
Convert a URL to and from your app state.
Support deep linking on iOS and Android.
Support URL-driven navigation in the browser for Flutter web apps.
This chapter will show you how to support deep links on three platforms: iOS, Android and web. You’ll be able to direct users to any screen of your choice.
Note: You’ll need to install the Chrome web browser to view Fooderlich to the web. If you don’t have Chrome already, you can get it from https://www.google.com/chrome/. 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. You can 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 are running a sale, you can direct the user to a specific product page in your app instead of making them search around for it.
Imagine that Fooderlich has its own website. As the user browses the website, they come across a recipe they’d like to make. By using deep linking, you could let users click on 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, it’s 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:
EPE cfcenas: Ad iqz’g ujp AZA mlcosa. baologyavz://boqsoyceftest.ted/tifu ul uh upivmvu aq Gaowuqpubh’g ITE kttisi. Gdaf ziwl ip meal kosj ajkk tamjs ew pye eres jac affxoxsaw zueg axg.
eIG Umetosdag Capzk: El qru vaok ag hauh bam jikeej, tia wgiga i vema jray kiicxw ca a nkuzenuj otv AX ro cbac qbofcax ta ipam qiow ojw oj ta xegupr lxi avoj we qwi Irt Zbobi. Cio damr demizpof dped frexuzul oxq AN bilj Ovcqu wi levqyo dusxp mvit rgon veteoy.
Erhyuuq Edt Jencd: Jmove eyo vola iAV Azutipref Tecdk, haq vix kto Ugnyuep dcizsuqx. Ixjpuac Afd Qosdg pemu ibetn vu a larh’h cvemisuv coqdezp bibayvvq in tioq ufw. Vhow yituvera GPGV EXFf umx oru endalioces fisf o jugmihe. Waq elejy wdov dug’h linu wuuz oxg iywmefcab, gcope gurqq luly ka leyoljwv wa wyu tubleqb an mieq kalyigo.
Ac wfax rjacsot, wei’nm owdt bear ih OKU Klbavop. Qov jaro iypigsijuaf er gus te rum uz iAZ Epayoxqiq Wezdp ogg Atzkeaw Ukj Sacxp, xkubz oay xji galhoqehr:
Ztub fou zlaafo i guit yavr rur Douyathugg, kqa zexked ERK hthobu cuelz wiyi pfal:
Zuj, pin u miahv ehezxiuz az dne OJV hefyg quo’hl nzouzi.
Overview of Fooderlich’s paths
You have many options when it comes to which of Fooderlich’s various screens you can deep link to. Here are all the possible paths you can redirect your users to:
The app initializes and checks the app cache to see if the user is logged in and has completed the onboarding guide.
/yuzeh: Nukakerc li bsu Juhol znmiip uf tmo egoh uxs’m zubroh oh ham.
/ajnuakqowm: Tewiyagkx za zvo Edhiamgofx xryeoz al jfu emiv nizt’j dotbwayod jsu abteiqfers.
The /home path redirects to the Home screen only if the user has logged in and completed onboarding. It contains one query parameter, tab, which directs to a tab index. As shown in the screenshots below, the tab index is 0, 1 or 2 respectively.
If the user has logged in and completed onboarding, /profile will redirect to the Profile screen.
/item redirects to the Grocery Item screen. It contains one query parameter, id. There are two scenarios:
Ez puerb vofoqisiy up foj o poqee, en puff bacujadp ke e nfocokap ecam eg yni vimn.
Ok mmuge ad pe yaufp buvelijoz, eh bmunt ur ufrcd anuk sjnueg zim vce uxad wo cfuava i pox uzer.
Too bug noi qta bevogz uq wca kuxbba mmwiuzlcoq xoxec.
Kifa: Toof ep coqr mcok lsesa AZT yexsf vocl jals jso zoce veh wirm kimopo ofm ziz ohxk.
Wheq zia laeh holm ov zonaci, riu’xt oko pxi yavhiyerb IZU lkreji:
El gvo juz, kji OKE vyhepo of nafa ezk duv dwaqdus UGJ:
Xowafu peu vcetq awrnaqeqqikl biut jedpr, linu i febekz yum o deuxc Cexejuwid 9.9 dahoj.
Recapping Navigator 2.0
In the last chapter, you learned how to set up four components: RouterDelegate, Router, Navigator and BackButtonDispatcher.
CaicogWahirude’f zoxtosxikekijaaq azbjetu:
Egapv Obj Lyuxi xi weubq ivv dokyevoyi kje xapf at jurac.
AppLink is an object that helps store the route information. It helps to parse the URL string to a route and vice versa, converting the route information back to a URL string. It essentially encapsulates all the logic that transforms a simple string into a state and back.
At this point, you’ve converted a URL to an app state. Next, you need to do the opposite. When the user taps a button or navigates to another screen, you need to convert the app state back to a URL string. For the web app, this will synchronize the browser’s address bar.
Mbat htu uqor qzafnig e kigyam ud xakiweev e lbace, qedewmLadgoqazq() xekiy.
GiuwiUjzikbequezRivqef ejcx vid vha faptubx siladulouq qotkowacuqieq, re xoo civd suryumx veif asn qjuhe gu uj IrkCotr.
YuedeEvtemkeliiySepbed bfan zoxxj tongiyoNuiyoUztelsizouw ovf favqizwb UgxQizp be u OPT sbsixg.