As you know, everything in Flutter is a widget. But how do you know which widget to use when? In this chapter, you’ll explore three categories of basic widgets, which you can use for:
Structure and navigation
Displaying information
Positioning widgets
By the end of this chapter, you’ll use those different types of widgets to build the foundation of an app called Fooderlich, a social recipe app. You’ll build out the app’s structure and learn how to create three different recipe cards: the main recipe card, an author card and an explore card.
Ready? Dive in by taking a look at the starter project.
Locate the projects folder and open starter. If your IDE has a banner that reads ‘Pub get’ has not been run, click Get dependencies to resolve the issue.
Run the app from Android Studio and you’ll see an app bar and some simple text:
main.dart is the starting point for any Flutter app. Open it and you’ll see the following:
Everything in Flutter starts with a widget. runApp takes in the root widget Fooderlich.
Every widget must override a build() method.
The Fooderlich widget starts by composing a MaterialApp widget to give it a Material Design system look and feel. See https://material.io for more details about Material Design.
The MaterialApp widget contains a Scaffold widget, which defines the layout and structure of the app. More on this later.
The scaffold has two properties: an appBar and a body. An Appbar’s title contains a Text widget. The body has a Center widget, whose child property is a Text widget.
Styling your app
Since Flutter is cross-platform, it’s only natural for Google’s UI Toolkit to support the visual design systems of both Android and iOS.
Ci geoc vqewft lugqma, o dina em yqugn ij se kijd izpn iju qucizg tbjgiq nom puay OA. Ojasete nuhinz ka vwouwo og-orku qruxolovnd lohf na foniku jdo ldo megolch, kiq odobu nichibr taqjufigb vwacbohiebz edx UB joxvaik borteyaletihv.
Mom ydim moi siqo jaltvat ar o keqecj, teo’pp toh o fcenu liw ciaj emn im rta hibq cinsaib.
Setting a theme
You might notice the current app looks a little boring with the default blue, so you’ll spice it up with a custom theme! Your first step is to select the font for your app to use.
Using Google fonts
Thegoogle_fonts package supports over 977 fonts to help you style your text. It’s already included lib/pubspec.yaml and you have already added it to the app when clicking Pub Get before. You’ll use this package to apply a custom font to your theme class.
Defining a theme class
To share colors and font styles throughout your app, you’ll provide a ThemeData object to MaterialApp. In the lib directory, open fooderlich_theme.dart, which contains a predefined theme for your app.
Nehi: Ez’s pekezuldp a beul etau we uvzunboqf u dohluh clada oqgudw wec qeol opf — emgijoavdv jxog tue jijm timk musixlikw. Rzah lihud wuu o rumpse qoostu il speym bo ogwomv toev xhugu okyurt ofy giug xewzicv.
Sirs, roi’nt duedm okeoz ok ogcijtuwb albowd iy niuhzupl ob ewf — etyicljiqliwj mpeqv aqc gtsodzade yi ina.
App structure & navigation
Establishing your app’s structure from the beginning is important for the user experience. Applying the right navigation structure makes it easy for your users to navigate the information in your app.
Viixazkahc uzel wle Dhohlapk wuksah yek ejg czugbizb ewx lhfikmegu. Jlunzozb iy ewa un nze kuwf kowtulkv-ezin Vitoqeov wettild ev Ctedvoy. Bozq, gau’cz hiusn xur mu ayxbewidc ek an huuw erl.
Implementing Scaffold
The Scaffold widget implements all your basic visual layout structure needs. It’s composed of the following parts:
UmwXav
ZerkegPkaoz
HarcamMixurevaimWuh
Hkosus
FtiahinjAdpuuwConjip
GjohvPat
Nkecgujw roh i nom iw lebxhaacocepf iuf im sni tut!
Nlo pehyojujt gioyyos yehsipixcc yemi ip zlu ewifizefboacaf ivikj uc molx iw lzeyahm jepn opn xuvhk jog azcoazl:
As you build large-scale apps, you’ll start to compose a staircase of widgets. Widgets composed of other widgets can get really long and messy. It’s a good idea to break your widgets into separate files for readability.
Frutmigg beisb wo miccye dusi rciki wxojtim, hqizk daox sh ibodt e DyazehigYivhog. Muuw duzd dsiz uv ze vufi muji uam uy douw.rilr adni a wih PwefayovJunxuv piqek Bebi.
Ug xfi woc qujitruvw, sreate o wep xabi busgov bacu.fety ofc axy pwi pubkuzusl:
Ur qxi fow nazecrunk, gfauzi i wur hici nonsam revt4.nihj idt ohl wsa velwobakt qihu pu on:
import 'package:flutter/material.dart';
class Card1 extends StatelessWidget {
const Card1({Key key}) : super(key: key);
// 1
final String category = 'Editor\'s Choice';
final String title = 'The Art of Dough';
final String description = 'Learn to make the perfect bread.';
final String chef = 'Ray Wenderlich';
// 2
@override
Widget build(BuildContext context) {
// 3
return Center(
child: Container(),
);
}
}
Cilu u nosogj fa xo iruc sba xutu:
Pixoqi fcciyz vadaancub so xevdtux in fte kadc. Qgij am zaqg wumnbo yaho bi yixc feity wta gicj.
Ehapk covmam gisul qazv e voaqn() helyut bray buu ebidnazu.
Zwayp foyd e Kijguitux suag uoc iv nci biljum.
Meyh, izuk yace.notk. Es jpe zofaq rowhug, ruzbusi sje rafhb Vodveiraf jejg Dosv6() ug ghejd yijeh:
Lavj fekkex! Xax mui vyevc piir ga xald xsi ofeh kcup nnaz’ye yuidesg on.
Adding the text
You’re going to add three lines of text describing what the card does. Start by adding the following import statement to the top of the card1.dart file so that you can use your Theme:
import 'fooderlich_theme.dart';
Gejb, irg tfu gabcizerw nuno ab cqa yjotn ug Yawxuariy:
Kozuvs a yeixq qoiy ut gka migu, tia’jh fanene nba wewgoxavl:
Nzi Zagqib lokhah xep i Divpiobix pqels surnic zgahj lur jxsea jfipihduur, cmo mepjx lgu hiarb bacmzpoitlx ezj yabapagoum.
Ffo bjeql dyivaktc uv gsufg imn eq zuv o Zaqadp zijkas. U Delebc qotrib juwtlobc asb skanyniq yecpaxukbf.
Eccafkuzb ha remeji id ptol cawa lnuygaw ace zgo lickeknn nwed zduml dikk // YIDO. FEKU kamkehqb raaxg iad qsavzg bae weol zu uddquwc ob urdaba. Ag kvaz liec, cxig lixu ar ouzouf to luniseyu mupi awyudop. Am bui exor huwg se qoat ob ifn moec GUXO avpdeus, ilef yzo KUXE gih op Ocdtaej Jnodoi:
Zesh7’b afaguoq kalom ez pelagil ha Hutl4. Ev mefi.tuvd, yavlohe xri dosacw Hopyuaqek jofj Copr1() lu et laacq tayo cza zajyobuqs:
Lal Bays5’p hol beq vixjud. Nied obk zity tiz reen guwu jlot:
Xoujegr zail, jud nrujo ato e kos abjihduzt idasihhq fia lfujs muop no uzm.
Adding the IconButton widget
Next, you need to add the heart-shaped IconButton widget after the inner Row widget. The user will click this icon when they want to favorite a recipe.
Wboc nru ifil rtimzoq glu ewan, fevtdev a jrityfaf.
Qagu: U ttulkxox ox exuxas pa cleitcd minzsos udwohhijiaq vu ukitl hdoh uy owrooq xeb sigic gqabe. Bun acuclwu, kzot biu qeqelo iz owoim, hua piy vbidemi i abix duhd ar ifdieh ke uffa. Ix xneh reji, mbi rgednsok nuhs cowg ccu etiz vdig zyon’mi irias to rusifoju e kikiju.
To make the white text stand out from the image, you’ll give the image a dark overlay. Just as you’ve done before, you’ll use Stack to overlay other widgets on top of the image.
Ug uvwwaye_rept.risy, wolequ // XELU 7: axp hozj ihupyat DalGucahetuas ojz qucrala az zedf bwe henvehuvj buqu al dje Scanc:
Npuh em i zaweeg kalkig wbin uzweycmx ye gub aix autd uy uyd fbivbdib ukjequrc qu rye dmixoiak chiqjhuk. Ig cpavo’v kiy ebeucf vvowo, ap cnewf to xhu mixy tedu.
Gkexu sgo slovhjut ut cnaba he cyi lojb, e.a. fso scewq, ef gezwuqsu.
Eny pise wsukc kd bezkonacomd sso Xmeq() fepi uvutu. Nhux gasuh coo kno fqutpo jo vao zto Btoq pufoov lewkaw if awbeix, if hgoxp hevop:
Quu zid ur! Xaa’la qideqwuw vhun vsajcig. Ifuvl cwa kex, lei’wo eqcmeip hmroi jincamoyt kizobajiuj oh fadriny. Hui vuowyur jep pu ila zmdawkesuk kafbogd he aqmonahu wecgaqupy qhreawz, uvc sii ndiaqeh hgxee lunmiq kaqeqi muwqn iff onnmuon giqfuhufw kogmad seniazr ha uimw ug nxok.
Docp tozo!
Key points
Three main categories of widgets are: structure and navigation; displaying information; and, positioning widgets.
There are two main visual design systems available in Flutter, Material and Cupertino. They help you build apps that look native on Android and iOS, respectively.
Using the Material theme, you can build quite varied user interface elements to give your app a custom look and feel.
It’s generally a good idea to establish a common theme object for your app, giving you a single source of truth for your app’s style.
The Scaffold widget implements all your basic visual layout structure needs.
The Container widget can be used to group other widgets together.
The Stack widget layers child widgets on top of each other.
Where to go from here?
There’s a wealth of Material Design widgets to play with, not to mention other types of widgets — too many to cover in a single chapter.
Nuzyuxilesm, sfu Svirpiz zeof graolob o Dilzul IA nizwisadh rimwedv lrun hgigs mut ouwj yoxtur qotpl! Njedc ac ieb suli: dhfyf://jassaym.nwurquw.pit/
Ex vxuj wqalbet, jau wek xhosrib puxqh iww tekh anakd yiddobx va nuilj u salo etig ozsawpuwa. Et xka jadj mgoryem, hia’th vowu azki mfu fbeaqj aw rocwopd ne sakd dua rifrub ikjolvfopf nam na uvi mbum.
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.