Unit 3 Widget
Unit 3 Widget
UNIT 03
Application
Mobile
INTRODUCTION
TO
WIDGETS
What are Flutter Widgets?
A flutter mobile app consists of multiple UIs with each UI built out of
one or more widgets.
These widgets are nothing but elements of interaction between the app
user and the application.
WIDGETS Note: element of interaction used to describe widget.
A graphical widget (also graphical control element or control) in a
graphical user interface is an element of interaction such as a button or a
scroll bar.
Controls are software components that a computer user interacts with
through direct manipulation to read or edit information about an
application.
WIDGETS
VISUAL
REPRESENTATION
OF THE
WIDGET TREE
1. Visible (Output and Input)
2. Invisible (Layout and Control)
1. Visible widget:
TYPES The visible widgets are related to the user input and
OF output data.
Some of the important types of this widget are:
WIDGETS 1. Text
2. Button
3. Image
4. Icon
1. Visible (Output and Input)
2. Invisible (Layout and Control)
2. Invisible widget
TYPES The invisible widgets are related to the layout and control of
widgets.
textDirection:TextDirection.ltr,
style:TextStyle(fontWeight:FontWeight.bold,
color:Colors.white,fontSize:20.0,)) );
}
1. Visible widget:
Button
Buttons are the graphical control element that provides a user to trigger
an event such as taking actions, making choices, searching things, and
TYPES many more.
OF
They can be placed anywhere in our UI like dialogs, forms, cards,
toolbars, etc.
WIDGETS Flutter provides several types of buttons that have different shapes,
styles, and features.
We can easily apply themes on buttons, shapes, color, animation, and
behavior.
1. Visible widget:
Button
Types of Flutter Buttons
Flat Button
TYPES Raised Button
OF
Floating Button
Drop Down Button
WIDGETS Code:
child: FlatButton(
TYPES widget.
OF
Image − Generic image loader using ImageProvider
Image.asset − Load image from flutter project’s assets
OF
height, double − Height of the image
alignment, AlignmentGeometry − How to align the image within its
WIDGETS bounds
1. Visible widget:
Image
The most important properties of the Image widget are as follows
image, ImageProvider − Actual image to load
TYPES width, double − Width of the image
OF
height, double − Height of the image
alignment, AlignmentGeometry − How to align the image within its
WIDGETS bounds
1. Visible widget:
Image
Image.asset('assets/tablet.png'
height: 400,
OF Image.file(‘Newfolder/tablet.png'),
Image.memory(‘Pendrive/tablet.png'),
WIDGETS Image.network(‘link/tablet.png'),
1. Visible widget:
Icon
An icon is a graphic image representing an application or any specific
entity containing meaning for the user.
WIDGETS
1. Visible widget:
Icon
OF default,
bottom: TabBar(
tabs: [
WIDGETS Icon(Icons.camera)),
Tab(icon:
],
),
body: TabBarView(
children: [
Icon(Icons.camera,
color: Colors.black,
size: 70,
semanticLabel: ‘Camera',
Invisible (Layout and Control)
2. Invisible widget
The invisible widgets are related to the layout and control of
TYPES widgets.
It provides controlling how the widgets actually behave and
TYPES
property mainAxisAlignment and crossAxisAlignment.
The column's cross-axis will run horizontally, and the main axis will run
WIDGETS
Invisible widget
2. Row:
This widget arranges its children in a horizontal direction on the screen.
We can control how a row widget aligns its children based on our choice
TYPES
using the property crossAxisAlignment and mainAxisAlignment.
The row's cross-axis will run vertically, and the main-axis will run
WIDGETS
Invisible widget
TYPES
OF
WIDGETS
Invisible widget
3. Center:
Center widget comes built-in with flutter, it
aligns its child widget to the center of the
TYPES
available space on the screen.
The size of this widget will be as big as
WIDGETS
widget by placing it as the child of
the Padding widget.
The Padding widget adds empty space
around any widget by using the
abstract EdgeInsetsGeometry class.
Invisible widget
5. Stack :
Stack widget is a built-in widget in
flutter SDK which allows us to make a
TYPES layer of widgets by putting them on
top of each other.
OF We might want to show some text over
TYPES
Widget supporting a single child:
The single child layout widget is a type of widget, which can have only
OF one child widget inside the parent layout widget.
LAYOUTS These widgets can also contain special layout functionality. Flutter
provides us many single child widgets to make the app UI attractive.
The list of different types of single child widgets are:
For example, Centre widget just centres it child widget with respect to its
parent widget. And child at any given place inside it using different option
like padding, decoration, etc.
Single child widgets are great options to create high quality widget having
2. Widget supporting multiple child:
In this category, a given widget will have more than one child widgets and
the layout of each widget is unique.
For example, Row widget allows the laying out of its children in horizontal
TYPES direction, whereas Column widget allows laying out of its children in
vertical direction. By composing Row and Column, widget with any level
OF
of complexity can be built.
Let us learn some of the frequently used widgets in this section.
LAYOUTS
Row − Allows to arrange its children in a horizontal manner.
Column − Allows to arrange its children in a vertical manner.
ListView − Allows to arrange its children as list.
GridView − Allows to arrange its children as gallery.
MaterialApp:
MaterialApp is a container for your entire Flutter app.
It sets up the app’s main structure and provides essential features and
services.
Think of it as the foundation upon which you build your app’s UI and
METERIAL
functionality.
The MaterialApp widget provides a wrapper around other Material Widgets.
We can access all the other components and widgets provided by Flutter SDK.
APP
Text wedget,
DropdownButton widget,
AppBar widget,
Scaffold widget,
ListView widget,
IconButton widget,
TextField widget,
Padding widget,
ThemeData widget, etc.
These all widgets that can be accessed using MaterialApp class.
Scaffold:
Scaffold is a class in flutter which provides many widgets or we can say
APIs like Drawer, Snack-Bar, Bottom-Navigation-Bar, Floating-Action-
Button, App-Bar, etc.
Scaffold will provide a framework to implement the basic material design
layout of the application.
SCAFFOLD
Properties of Scaffold Class:
App-Bar: It displays a horizontal bar which mainly placed at the top of the
Scaffold.
AppBar uses the widget AppBar which has its own properties like title,
brightness,
Flutter Container:
The container in Flutter is a parent widget that can contain
multiple child widgets and manage them efficiently through
width, height, padding, background color, etc.
It is a widget that combines common painting, positioning,
FLUTTER and sizing of the child widgets.
Generally, it is similar to a box for storing contents. It allows
CONTAINER many attributes to the user for decorating its child widgets,
such as using margin, which separates the container with other
contents
A container widget is same as tag in html.
It will wrap the child widget according to the specified height
& width.
A basic container has a margin, border, and padding properties
surrounding its child widget, as shown in the below image:
Flutter Container:
FLUTTER
CONTAINER
THANK YOU END OF UNIT