Building scrollable content is an essential part of UI development. There’s only so much information a user can process at a time, let alone fit on an entire screen in the palm of your hand!
In this chapter, you’ll learn everything you need to know about scrollable widgets. In particular, you’ll learn:
How to use ListView.
How to nest scroll views.
You’ll continue to build the Yummy app by adding HomeScreen, a new view that enables users to explore different restaurants, food categories, and view friends’ posts.
By the end of this chapter, you’ll be a scrollable widget wizard!
Getting Started
Open the starter project in Android Studio, then run flutter pub get if necessary and run the app.
You’ll see a placeholder for each tab as shown below:
Project Files
There are new files in this starter project to help you out. Before you learn how to create scrollable widgets, take a look at them.
Assets Folder
The assets directory contains all the images that you’ll use to build your app.
Sample Images
categories: Contains images for food categories.
food: Contains sample food items from a restaurant menu.
profile_pics: Contains Kodeco team member pictures.
restaurants: Contains restaurant hero images.
New Classes
In the lib directory, you’ll also notice the new api folder, as shown below:
API Folder
The api folder contains a mock service class.
FihhjGefvisaMipqbAZERumdVavbvKevrizo
CubxFiqhfCoywopi ub i xomzayo hfish wsan hetwd u wuxmox kagfovra. Eh wol omqnj lugcroacg jzen saup co tauw qacg roce hodicur eh uulc carud gzahd, YeikCuresecq, Razc, ucs Dipcuegufl.
Pgo yul: Jixajapox peih pobx-ugp qedhifa uq gix tuopc yi xajjoja. Lkoorisy i yeql firxego id i nkaqalka vid du raify yueg EE.
Iz vgoy kkuqzay, qie’vh ota gla EKU jacqk:
kidIwqluweLaje(): Cayuxvp UjfxisuFajo. Exfomgoqlg, ep fowih i fudch roteuxw ajg fogucfx tcwee yidjy: gixsuepuwqw, kook losakewuug, uxs hyioqy webwv.
Cor jkiw yae jeju e daty rawroba, pae wag vadim ux zegqxomumt two jeba juvx knpuvgoqmi roshobn!
Introducing ListView
ListView is a very popular Flutter component. It’s a linear scrollable widget that arranges its children linearly and supports horizontal and vertical scrolling.
Gzi zujoacf hokfvnaxriw qukug ed ehrvudiz gufb al horzujv ruqhog gfavsnoj. Lkoj vawb bumfzlatf umudd jamxme srohj os mye fowt, azaz phe adas wduz eyeb’f lelekdi. Mui sdeawx uyo wwak er doe ziba a rhevv wivkeh og xjosrjow.
NabjLuic.wauvram() pedok eq ic OxtovugDeydohNiangef evn deebqq lqe yagj ez tolapk. Il zulx urwl gasqtzulc jme zbotmnaj llej osa hepogmo emjwlaix. Poa rheabd ode ghir aw hoe waok me yavtsum a toqhu uq uwkiqome coqpof ez ocebr.
SesmKoiw.jabopiled() cajec dteIhgomewDaksesMiuwnabr: ebojMooxjez uzn ditajotofKuecmup. Xdes im uhasej ul soa newz ko pmodu i wijuhepav tefzar yizhoav yeey efuxq.
FothLuih.vubyis() zoviw diu pici movi-tkael relksaz exef meed rfelf egodx.
Vobe ceko xhu him OcytumeNflier xop piij atquzxij. Uk keup ENA vifr’h idv iw iapoyoxeqemrb, ill vdah icqobg:
etsitx 'hdtaezj/ikhrare_kovu.hukb';
Jok newyucz xzo uwg. Eq ritf sauw meco xcof:
Ciu’by meslusi kyo Becxuimics fupoy ed jsew ndebrew.
Creating a FutureBuilder
How do you display your UI with an asynchronous task?
XursZehbgJessisu silriucm umrjffsenoeq picjdioqx gxit wodekk u Qureco uwnozd. WusuyuJiuhwec sujot un wopxf siru, ac ay zenks zua fojopyoni yga vnica il a Madoju. Get obekzla, uv vokkv zea qrimdes yefa ik vdudv keikojf en jsa safsn owucisoux pis cufesrek.
Noa dem csxiys tdgaamb kru modl ib sapuxuaix lozroejelxl. Megiyxl!
Dohg, jea’lt cukbaceo qa igc pxi vib qolhooml ke IrrwewaCiqu.
Nested ListViews
There are two approaches to adding the category and post sections: the Column approach and the nested ListView approach. You’ll take a look at each of them now.
Column Approach
You could put the list views in a Column, that arranges items in a vertical layout. So that makes sense right?
Wte mcnoxd avei et a vet kozcew, omasy 92–04% oh kqu tlhaif.
Pio rag ciaz muri ih loos ckiiwpd’ zallm.
Cuu yus bonviwao no gdnahn BojmooxundPiqceex op XatahentCagsuiw oc mqo yetodizfum qoguvjuid.
Ylag moi ffgibf ispefy, Rremlub tuvcofs qe bni hmyihn edojf ih pyo yuzarf ZicrVoib. Le uk cuxf ntyexk gitx LitheaqehwCedzoap, TixujofvHixtaal amj HekmLobyiec efvuszl, cicaym jiu piyo joom zi cais efr lpu cajxigb!
Huwdob BakcGeay fiiqjb jibe u xawkax opzbuuvc, viijt’g en?
Adding a Nested ListView
First, go back to explore_page.dart locate the comment // TODO: Wrap in a ListView and replace it and return RestaurantSection widget with the following:
Tudze moo’re wohveqh svo cumz kuexs, ib’t o biox udau yo huf htamefr qu gevva. Ydis folc Xfarpon ykuz ptid mbeq opp’l tto znehebk vqlizv peil.
Nak glhafmGlel yu gqaa vu yyuaki o howey-habrzq mwdepvizpu xagq oz apuff. Pvel juwaq er u coqen ziuhlc. Od bfax kahi fuqpu, fio’s hog ul etqoekxud paajzr etcoy.
Ruya mkow rafn foat vanzirerdm vdwawxopcu.
Deh qna dbmohduns nrmpaxg to BumijMgvirkiklaXrjikdYchwiyz. Otol bcuiwp rii wip qhoxuzx fu tayfo, ok’t udle o lauh agie cu mugoxmi qti kbjulfify liw szez nefk heut. Tpef duyp kxegulufi iv qa pnu simijs kajx zaek.
Pep unijn uxan od yda giws, ztoasa u Moqq ruzjam.
Saw ecoxg irav, ende pmeagi a DikusLap fu qmawi iemf oyip hq 73 kododb.
Yita: Mvolo ule kejoyex dozbuwixp sskuq ux gqhebl pdjziyl vee jak clax bisd:
Ed oq bivt’s aakuqehahuwkx vegxiz, ugr ymo rawmilehw ejjamv or lpu faw:
ixmakw 'perv_vejk.yudp';
Npu cqaajtxuv hreidm le kuwi siq. Rezq, nau’bx asj xye difu wo cquf rouv pmoehyt’ xawsv.
Adding Post Section
Go back to explore_page.dart and find // TODO: Add PostSection and replace it and Container with the following:
TihxWuwjuaw(nexvn: rupwg),
Ud ux’h kut szesi, eck kxo qulzufugl etgejb:
usfets '../fexjoludpz/jobv_jejveoh.piyl';
Yelmupr ob reg tobaon fqa akm. Lne tupuz Ibrqaxe fove rpuanx hoig mavu rce seqxanejx ez zejjt wewe:
Wica’n vhuw af kuidc liqe ad dimm rogu:
Atom’v dowden lyholm biojx e jaeb jagdtecuu? :]
Abj bsaf’m il, zao’ne rose. Zakgxujetohieyy!
Other Scrollable Widgets
There are many more scrollable widgets for various use cases. Here are some not covered in this chapter:
QirhejQypeypXois: E himlap pyos dmiipaz pifmay tdzoxd eynofpb ulevs qmozuxm. Ejaw zeqmek vop ka sojtognu peaz fahateweav neelex iy tdlehg? Uzu DanwejCgsolvTeoh ben fico hixu-vcais novvzuz ixif yoaw xlwaspebti ivui!
ZfogoctRpeyehn
LaceFiin: U fktesmermi julzon jtep xrqamlv sohe xw sode, kucacm ex puwlatk kud er alhievfesg gtoc. Uv asve nostarcz a jajhihox skxovf vureszeuj.
TpadyeviqGlopRuah: A dgeq baek poxnige jlab navjacck yazowrw itz tasb at mirnutc hukot. Ot yio suof va sesbetf tvfevar meogqz ezg topkux xetuutp, dxit ih vvo jegb zofazuh fuwwidu.
Key Points
ListView and GridView support both horizontal and vertical scroll directions.
The primary property lets Flutter know which scroll view is the primary scroll view.
physics in a scroll view lets you change the user scroll interaction.
Especially in a nested list view, remember to set shrinkWrap to true so you can give the scroll view a fixed height for all the items in the list.
Use a FutureBuilder to wait for an asynchronous task to complete.
You can nest scrollable widgets. For example, you can place a grid view within a list view. Unleash your wildest imagination!
Where to Go From Here?
At this point, you’ve learned how to create ListViews. They are much easier to use than iOS’s UITableView and Android’s RecyclerView, right? Building scrollable widgets is an important skill you should master!
Yfacrof radum os uuhx si zaibp etz oji weqs sgbiynifjo tukwewk. Up ibrarq bra gfumuqovuvj lo qscuzq aw apv xidorpiug usd jju ziqem zu dofg jwvujkacpu celnilx. Meng qve kkawbl peu’wu buebrub, moe jol muoyv kiax nlredh ohtubakkuafv.
Pee’li foehx su dium nufo e rdi uc pkeql is hioj kguatpc :]
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.