Chapter 04 A Flutter framework
Chapter 04 A Flutter framework
FRAMEWORK
ICT425 MOBILE APPLICATION DEVELOPMENT
PRASHAYA FUSIRIPONG (PH.D.)
1. Flutter project structure
2. Introduce the widgets
3. Built-in Flutter widgets
OUTLINE
4. Types of widget
5. UI as Code
6. Stateless and Stateful widgets
FLUTTER PROJECT ENVIRONMENT ON ANDROID STUDIO
• Selected simulator
• Running
• MaterialApp widget: Defines the overall appearance and behavior of the app
Properties: title, theme and home
title: sets the app’s title
theme: defines the app’s theme, including colors, fonts, and styles
home: sets the initial widget to display when the app starts
• MyHomePage class: The main widget that displays the greeting message
Contains the build method that returns the widget tree for the home page
• Scaffold widget: provides a basic layout structure
for the app
Properties: appBar, and body
appBar: defines the app bar at the top
Body: sets the main content area of the app
• Hot reloading
Making change the source code and rerun it when application is running on emulator device,
browser or physical device
Recompiling and reloading with the same state, and same data
It makes the development cycle ridiculously fast
• Debugging
“step over” / “step into” / “force step into” / “step out”
INTRODUCE THE WIDGETS
• Widgets can be understood as the visual representation of parts of
the application (not only the visual)
• Widgets are put together to compose the UI of an application
• The main characteristics of the widgets UI in Flutter are:
Composability:- Flutter choose composition to be a simple, well-defined and flexibility
Immutability:- Flutter is based on the reactive style of programming (widget instances)
• A Flutter widget may have a state associated with it, and when
the associated state changes
The terms state and reactive are well known in the React style of
programming
INTRODUCE THE WIDGETS
• Flutter widgets are everywhere in an application
• A widget represents a part of a UI
• Widgets can be any of following:
A visual/structural element that is a basic structural element (button or text
widgets)
A layout specific element that may define the position, margins or padding
A style element that may help to colorize and theme
An interaction element that help to respond to interactions (i.e.
GestureDetector widget)
INTRODUCE THE WIDGETS
• Widgets are the basic building
blocks of an interface
• Flutter organizes the widgets in a
widget tree
• The widget tree is the logical
representation of all the UIs widgets
• All widgets is computed during
layout (structural info) and
rendering (screen) and testing
(touch interaction)
INTRODUCE THE WIDGETS
• Widgets are represented in the tree
nodes
Every change to widgets state
results in rebuilding the widgets
and the child involved
• Flutter’s built-in widget exposing
child or children properties,
depending on the purpose of the
widget
BUILT-IN FLUTTER WIDGETS
• Flutter’s foundation widgets
are the building blocks of
everything
• They fall into these major
categories:
Value widgets
Layout widgets
Navigation widgets
Other widgets
VALUE WIDGETS
• The value widgets can hold a value that maybe come from local
storage, a service on the internet, or from the user themselves.
• The value widgets are used to display values to the user and to
get values from the user into the app
LAYOUT WIDGETS
• Layout widgets give us tons
of control in making our
scene lay out properly
placing widgets side by side
or above and beneath
making them scrollable
making them wrap
determining the space
around widgets
NAVIGATION WIDGETS
• Navigation widgets will control one scene and then moves to the
next scene
• Navigation widgets as button that is located on tab bar / in a
drawer that slides in from the left side of the screen
OTHER WIDGETS
• Here are some miscellaneous widgets:
Framework Behavior UI
Xamarin C# XAML
React Native JavaScript JSX
Native Script JavaScript XML
Flutter Dart Dart
STATELESS AND STATEFUL WIDGETS
• Widgets describe what their view should look like given their
current configuration and state
• Types of widgets:
StatelessWidget: A widget that does not require any mutable state. Its
configuration and appearance are immutable after being create
StatefulWidget: A widget that can hold and change its internal state
over time. It is used for interactive elements that can change
dynamically
WHAT ARE ‘STATELESS’ WIDGETS?
• A stateless widget is one that does not have any mutable state
• The only area of focus of a stateless widget is the information displayed and the user
interface
• They deal with situation that are independent of the user’s input
• A stateless widget does not tell the framework when to remove it or rebuild it
• They create user interfaces that do not change dynamically upon updation in the
nearby values
• We use a stateless widget when we create an application that does not require
redrawing a widget again and again
STATELESS WIDGETS
• Structrue: StatelessWidget must override the build method to
describe the part of the user interface represented by this widget
• Use cases for StatelessWidget
Displaying static content like labels, icons, or decorative elements
Layout containers that do not require user interaction, such as
Containers, Padding, and Column
STATELESS AND STATEFUL WIDGETS
• StatelessApp and MyCustomWidget
are stateless widgets.
• The ‘Text’ widget inside
MyCustomWidget is immutable, and
its state does not change during the
lifecycle of the widget
WHAT ARE ‘STATEFUL’ WIDGETS?
• A stateful widget has its own mutable state that it needs to track. It is modified
according to the user’s input
• A stateful widget looks after twin things primarily, the changed state based on its
previous state and an updated view of the user interface
• A track of the previous state value has to be looked at because there is a need to self-
rebuild the widget to show the new changes made to your application
• A stateful widget triggers a build method for creating its children widgets and the
subclass of the state holds the related data. It is often used in cases where redrawing of
a widget is needed
• A stateful widget can change when
There is a user input included
There are some user interaction
There are some dynamic changes
STATEFUL WIDGETS
• Structure: A ‘StatefulWidget’ consists of two classes:
‘StatefulWidget’ class: This is immutable and can be recreated if the
parent widget tree changes
‘State’ class: contains the mutable state for the widget and the build
method that describes the part of the user interface