0% found this document useful (0 votes)
2 views

Chapter 05 Building Flutter UI with widgets - 1

The document provides an overview of building Flutter UI using various widgets, including Text, Icon, Layouts, Image, Input, and Button widgets. It details the properties and functionalities of each widget type, along with examples of their implementation. Additionally, it covers the hierarchy of widgets and how to effectively use them to create user interfaces in mobile applications.

Uploaded by

hsusandi.b65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapter 05 Building Flutter UI with widgets - 1

The document provides an overview of building Flutter UI using various widgets, including Text, Icon, Layouts, Image, Input, and Button widgets. It details the properties and functionalities of each widget type, along with examples of their implementation. Additionally, it covers the hierarchy of widgets and how to effectively use them to create user interfaces in mobile applications.

Uploaded by

hsusandi.b65
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

BUILDING FLUTTER UI

WITH WIDGETS
I CT425 MOBILE APPLICATION DEVELOPMENT
PRASHAYA FUSI RIPONG (PH.D.)
1.Text widget
2.Icon widget
3.Layout
OUTLINE
4.Image widget
5.Input widget
6.Button widget family
TEXT WIDGET

• Text widget can display a


‘string’ to the screen
 Text(“hello world”),

• Text widget have properties


to control over the text’s
size, font, weight, color, and
more with its style property
 Text will be modified style
with ‘TextStyle class’ via
‘style’ Text widget property
TEXT WIDGET
• TextStyle supports many
properties to change the style
of text in ‘TextWidget’
 color:- any of the valid 16+
million colors
 decoration:- underline, overline,
strikethrough, none
 fontSize:- number of pixels tall to
make the characters (default
size is 14.0 pixels)
 fontStyle:- italic or normal
 fontWeight:- bold or normal
 fontFamily:- family name
ICON WIDGET

• Flutter framework prepare the Icons class


to be used into the flutter apps
 The class has hundreds of static values like
Icons.phone_android and
Icons.phone_iphone and Icons.cake

• How to put a big red


birthday cake on
flutter app
LAYOUTS AND WIDGET HIERARCHY
• What is a Layout?
A layout in Flutter refers to how widget are arranged in relation to one another on the
screen. It involves position, spacing, and alignment to create the desired UI structure
• Widget tree:
In flutter, the user interface is built as a tree of widgets, where each widget is a node. The
parent-child relationship among widgets defines the hierarchy and layout of the UI
• Types of Layout widgets:
 Single-child layout widget
These widgets can have only one child widget. Example include Container, Center, Padding
 Multi-child layout widget
These widget can have multiple children. Example include Column, Row, Stack, ListView
TOP 20 MOST USED SINGLE-CHILD WIDGET IN FLUTTER
TOP 20 MOST USED MULTI-CHILD WIDGET IN FLUTTER
COMMONLY USED CONTAINER WIDGET
• A container class in flutter is a convenience widget that combines common painting,
positioning, and sizing of widgets
• A container class can be used to store one or more widgets and position them on the
screen
• A basic container element that stores a widget has a margin, border and padding
 Margin:- separates the present container from other contents
 Border:- Define a border of different shapes
for example, rounded rectangles
 Padding:- applies additional constraints to the padded extent
(incorporating the width and height as constraints, if either is non-null)
COMMONLY USED ROW AND COLUMN WIDGET
• Row and Column widgets align children horizontally and vertically as per the
requirement
• Properties of Row and Column widgets:
 children: This property takes in List<Widget>, that is a list of widgets to display inside the Row or
the Column widget
 crossAxisAlignment: CrossAxisAlignment enum as the object to how the children’s widgets should
be places in crossAxisAlignment. For Row it is vertical and for Column it is horizontal
 mainAxisAlignment: MainAxisAlignment enum as the object to decide how the children widgets
should be place in mainAxisAlignment. For Row it is horizontal and for Column it is vertical
COMMONLY USED ROW WIDGET
• Row can create a horizontal array of children
• Alignment properties: using mainAxisAlignment and crossAxisAlignment
 Row’s mainAxis is horizontal
 cross Axis to Row’s main Axis is vertical
COMMONLY USED ROW WIDGET
• Row can create a vertical array of children
• Alignment properties: using mainAxisAlignment and crossAxisAlignment
 Row’s mainAxis is vertical
 cross Axis to Row’s main Axis is horizontal
COMMONLY USED EXPANDED WIDGET
• Expanded widget can be taken as the
child of Row, Column, and Flex
 if we don’t want to give equal spaces to
our children widgets we can distribute the
available space as our will using flex
parameter

• Adjusts the size of its child to fill the


available space
• The first Container with flex: 2 takes up
twice the space of the second
Container with flex: 1
COMMONLY USED STACK WIDGET
• Stack widget allows children to be
layered on top of each other
• Useful for creating complex layouts like
overlapping elements, banners, or
floating action button
• Stack contains three children: two
overlapping Container widgets and a
positioned Text widget
COMMONLY USED LISTVIEW WIDGET
• A scrollable list of widgets arranged
linearly
• Ideal for creating long, scrollable lists
of items
• Each listTile widget displays an icon,
a title, and a subtitle, forming a
simple contact list
IMAGE WIDGET

• Displaying images in flutter app is a bit more complex than Text or


Icons
• All images can display in flutter app must involve as:
 Getting the image source
 Image embedded in the app (Never change it)
 Image fetched from the internet
 Sizing the image:- scaling image up or down to the right size and
shape
IMAGE WIDGET
• Embedded images
 Embedded images are much faster but will increase the flutter app’s install
size
 Embedded images must put image files in the flutter project folder
 Needed to modify the “pubspec.yaml” file to allow the flutter project accept
and get the image files from project folder

 Save the “pubspec.yaml” file and run “flutter pub get” to have the flutter project
process the flie
IMAGE WIDGET
• Embedded images
 The flutter app get the images to render on the screen by calling the “asset”
constructor
For example:- Image.asset(“assets/images/photo1.jpg”,),
 Tip……
‘pubspec.yaml’ file hold all kind of great information about the flutter project.
 The file holds project metadata like the name, description, repository location, and
version number.
 The file holds the lists library dependencies and fonts
IMAGE WIDGET
• Network images
 Network images are much more like what web developers might be
accustomed to
 Network images is simply fetching an image over the Internet via http
 Using ‘network’ constructor and pass in a URL as a ‘string’ type
For example:- Image.network(imageUrl),
 Network images are slower than embedded image
 Network images are live; any image can be loaded dynamically by simply
changing the image URL
IMAGE WIDGET
• Sizing an image
 Flutter framework will shrink the image
to fit its container as called ‘BoxFit’
property
For example:
Image.asset(
‘assets/images/woman.jpg’,
fit: BoxFit.contain
),
INPUT WIDGET
• Flutter framework provides widgets for entering data (Input widget)
• Input widgets are safer and give much control
• Input widgets do not maintain own state; we have to do it manually
• Input widgets don’t play well together until you group them with a Form widget
• Input widgets is to ‘text fields’, ‘checkbox’, ‘radio buttons’, ‘sliders’, and
‘dropdowns’
TEXTFIELDS WIDGET
• Flutter app probably want a TextField widget waiting the data from users entry
• TextField widget should have a Text label to represent the data meaning:
For example:
const Text(“Search terms”),
TextField(
onChanged: (String val) => _searchTerm = val,
)

• The ‘onChanged’ property is an event handler that fires after every keystroke
 TextField widget will receive a single value – a “String” (the value come from user is
typing)
TEXTFIELDS WIDGET
• ‘TextFields’ widget as fancy by using the ‘InputDecoration’ widget
For example:
return TextField(
decoration: InputDecoration(
labelText: ‘Email’,
hintText: ‘[email protected]’,
icon: Icon(Icons.contact_mail),
),
),
TEXTFIELDS WIDGET
• “InputDecoration” widget provides many properties for
decorating the input widget as follow below:
Property Description
labelText appears above the TextField. Tells the user what this TextField is for
hintText light ghost text inside the TextField. disappears as the user begins typing
errorText error message that appears below the TextField. usually in red. It is set
automatically by validation (covered later)
prefixText Text in the TextField to the left of the stuff the user types in
suffixText same as prefixText but to the far right
Icon draws an icon to the left of the entire TextField
prefixIcon draws one inside the TextField to the left
suffixIcon same as prefixIcon but to the far right
TEXTFIELDS WIDGET
• ‘TextFields’ widget as fancy by using the ‘InputDecoration’ widget
For example:
return TextField(
decoration: InputDecoration(
labelText: ‘Password’,
hintText: ‘Password’,
icon: Icon(Icons.password),
),
),
TEXTFIELDS WIDGET
• ‘TextFields’ widget as fancy by using the ‘InputDecoration’ widget
For example:
return TextField(
keyboardType: TextInputType.number
decoration: InputDecoration(
labelText: ‘Phone number’,
hintText: “000 458 8524”,
icon: Icon(Icons.phone),
),
),
CHECKBOXES WIDGET
• ‘Checkboxes’ widget have a Boolean value property and an ‘onChanged’ method
with fires after every change.
• The ‘onChanged’ method receives the value that user set
• ‘Checkboxes’ value is a bool as result
• For example:
checkbox(
value: true,
onChanged: (bool val) => print(val)
),
• A flutter ‘switch’ widget serve the same purpose as a ‘checkbox’ widget
RADIO WIDGET
• The ‘radio button’ widget can be selected one, the others
in the same group are deselected within the same group.
 So flutter framework provide the ‘RadioListTile’ widget to create
the group of radio button

• The ‘RadioListTile’ is a widget that combines a radio button


with a list tile.
 Each RadioListTile represents a single option in the list and
consists of:
 Title
 Subtitle
 An optional leading and so on
SLIDER WIDGET
• The slider is a widget to select a value from a given range
in the application
• The slider widget can be implemented by simply and
provide the range values
• The slider widget takes two required parameters:
 value:- the default value whenever the app is launched and
should be of type double
 onChange:- This function is triggered whenever the slider value
is changed are changed and we get a double value which
we can use for further process
DROPDOWNBUTTON WIDGET
• The DropDownButton is a widget that
we can use to select one unique
value from a set of values
• The default value of dropdown
button should shows the currently
selected value
• The dropdown button can even
include a down arrow icon on the list On clicking the ‘dropdownbutton’ widget,
it open a list of items
DROPDOWNBUTTON WIDGET
• Dropdownlist property

Property Description
We use this property to define various
items that are to be defined in our
items
dropdown menu/list. It is a list of items
that users can select
value Value is the currently selected item
We use elevation property to elevate
Elevation On clicking the ‘dropdownbutton’ widget,
the dropdown menu/list
This property is used to display an it open a list of items
icon
icon to the dropdown button
We use the style property to style our
style text in the dropdown menu/list like
color, fontsize, fontweight, etc
BUTTON WIDGET FAMILY
• Buttons are material components that provide the user a single tap facility for taking
actions, making choices, submitting forms, saving data, opening a new page, etc
• Buttons are triggered when the user taps on them
• Special features of a button:
 Easy addition of different child widgets for different purposes
 Easy theming of the button
 Easy addition of themed text and icons
 Provide action functionalities

• Types of buttons
 TextButton
 ElevatedButton
 OutlinedButton
 IconButton
TEXTBUTTON WIDGET
• Text Button Class in flutter are material component button widgets with no border by default
• Text button is a regular button with some text written as the label
• Parameters must be required:
 child: button’s label
For example:
child: const Text(“Text Button”),

 onPressed: the action to be performed on pressing the button


onPressed: (){
setState(() {
_txtclick = "Text Button is clicked...";
});
}
Noted: onPressed event can handle calling the new screen in flutter app
ELEVATEDBUTTON WIDGET
• Elevated Button hold is the slight elevation in their surface towards the screen on getting
tapped by the user
• Parameters must be required:
 child: button’s label
For example:
child: const Text(“Elevated Button”),

 onPressed: the action to be performed on pressing the button


onPressed: (){
setState(() {
_txtclick = “Elevated Button is clicked...";
});
}
OUTLINEDBUTTON WIDGET
• Outlined button widgets is in no way different from text buttons except for the
special feature of the border this class provides
• Parameters must be required:
 child: button’s label
For example:
child: const Text(“Elevated Button”),

 onPressed: the action to be performed on pressing the button


onPressed: (){
setState(() {
_txtclick = “Elevated Button is clicked...";
});
}
ICONBUTTON WIDGET
• Icon button is the button having an icon, and presses it does something
• Parameters must be required:
 icon: button’s icon
For example:
icon: const Icon(Icons.volumn_up),

 onPressed: the action to be performed on pressing the button


onPressed: (){
setState(() {
_volume += 10;
});
}
Thank you
Prashaya Fusiripong (Ph.D.)
Email: [email protected]
Department of Information and communication technology (ICT), International college

You might also like