Chapter 2 Flutter Basics Lecture 3
Chapter 2 Flutter Basics Lecture 3
The main concept of the layout mechanism is the widget. We know that
flutter assume everything as a widget. So the image, icon, text, and even
the layout of your app are all widgets. Here, some of the things you do not
see on your app UI, such as rows, columns, and grids that arrange,
constrain, and align the visible widgets are also the widgets.
Flutter allows us to create a layout by composing multiple widgets to build
more complex widgets. For example, we can see the below image that
shows three icons with a label under each one.
CONT..
In the second image, we can see the visual layout of the previous image.
This image shows a row of three columns, and these columns contain an
icon and label.
CONT..
Center(
child: Container(
margin: const EdgeInsets.all(15.0),
color: Colors.blue,
width: 42.0,
height: 42.0,
),
)
PADDING WIDGET
Pointers are the first layer that represents the raw data about user
interaction. It has events, which describe the location and movement of
pointers such as touches, mice, and style across the screens. Flutter does
not provide any mechanism to cancel or stop the pointer-events from
being dispatched further. Flutter provides a Listener widget to listen to
the pointer-events directly from the widgets layer. The pointer-events are
categories into mainly four types:
• PointerDownEvents
• PointerMoveEvents
• PointerUpEvents
• PointerCancelEvents
CONT..
It is the second layer that represents semantic actions such as tap, drag,
and scale, which are recognized from multiple individual pointer events. It is
also able to dispatch multiple events corresponding to gesture lifecycle like
drag start, drag update, and drag end. Some of the popularly used gesture
are listed below:
Tap: It means touching the surface of the screen from the fingertip for a
short time and then releasing them. This gesture contains the following
events:
onTapDown
onTapUp
onTap
onTapCancel
CONT..
Double Tap: It is similar to a Tap gesture, but you need to tapping twice in a short time.
This gesture contains the following events:
onDoubleTap
Drag: It allows us to touch the surface of the screen with a fingertip and move it from
one location to another location and then releasing them. Flutter categories the drag into
two types:
Horizontal Drag: This gesture allows the pointer to move in a horizontal direction. It
contains the following events:
onHorizontalDragStart
onHorizontalDragUpdate
onHorizontalDragEnd
Vertical Drag: This gesture allows the pointer to move in a vertical direction. It contains
the following events:
onVerticalDragStart
onVerticalDragStart
onVerticalDragStart
CONT..
Long Press: It means touching the surface of the screen at a particular
location for a long time. This gesture contains the following events:
onLongPress
Pan: It means touching the surface of the screen with a fingertip, which can
move in any direction without releasing the fingertip. This gesture contains
the following events:
onPanStart
onPanUpdate
onPanEnd
Pinch: It means pinching (move one's finger and thumb or bring them
together on a touchscreen) the surface of the screen using two fingers to
zoom into or out of a screen.
GESTURE DETECTOR
Flutter provides a widget that gives excellent support for all types of
gestures by using the GestureDetector widget. The GestureWidget is
non-visual widgets, which is primarily used for detecting the user's
gesture. The basic idea of the gesture detector is a stateless widget that
contains parameters in its constructor for different touch events.
In some situations, there might be multiple gesture detectors at a
particular location on the screen, and then the framework disambiguates
which gesture should be called. The GestureDetector widget decides which
gesture is going to recognize based on which of its callbacks are non-null.
Let us learn how we can use these gestures in our application with a
simple onTap() event and determine how the GestureDetector processes
this. Here, we are going to create a box widget, design it according to
CONT..