Chapter 3
Chapter 3
• There are kinds of List: fixed-length list (list’s length cannot be changed) &
growable list (size can be changed to accommodate new items or remove items)
• Dart List is an ordered collection which maintains the insertion order of the items.
• Dart List allows duplicates and null values.
• While an operation on the list is being performed, modifying the list’s length
(adding or removing items) will break the operation.
Create a List in Dart/Flutter
• How to create a List using List() constructor or literal syntax.
• How to add new items to a List.
Remove items from List in
Dart/Flutter
DropdownButton Widget
• A drop down button widget is similar to a drop-down menu that allows your app user to
choose only one value from a list. It depends on other Dart methods in its configuration
as you will see in the next example
DropdownButton Widget
setState
A widget’s state is stored in a State object, separating the widget’s
state from its appearance.
The state consists of values that can change, like a checkbox is
checked.
When the widget’s state changes, the state object calls setState(),
telling the framework to redraw the widget.
ButtonBar Widget
This widget is a horizontal arrangement of other types of buttons. For example, this
widget can include three or four of flat or outline buttons and arrange them horizontally
to appear as a horizontal navigation bar for your app
These buttons are children widgets for the ButtonBar widget , and it is a good idea to
use the alignment property with value : MainAxisAlignment.center which places
other children buttons as close to the middle of the main axis as possible.
ButtonBar Screenshots
PopupMenuButton Widget
App Structure and Navigation
The app structure is almost similar to the web site structure. The first
app interface which will open when users run your app is called the
main interface, while it is called a home page for the web site. In Flutter
development your main interface is the main.dart file. The main app
interface or screen must include links or routes to your other app
screens or your app parts.
App Structure and Navigation
In your app, you will use various navigation techniques to move from
one screen to another. For any app to be successful, it should be easy
to use and have a variety of navigation techniques. This would help app
users to reach and use app data in a simple and easy manner, using
friendly app interfaces
App Structure and Navigation
Navigate A New Screen and
Back
Mobile apps typically reveal their contents via full-screen elements
called “screens” or “pages”. In Flutter, these elements are called routes
and they are managed by a Navigator class or widget. Flutter navigator
takes you on each of these routes to see each of these screens.
The Navigator class manages a stack of Route (screen) objects and
provides methods for managing the stack, like Navigator.push and
Navigator.pop.
Navigator.push() method is used to navigate to the second route.
Navigator.pop() method is used to return to the first route or screen.
Using Navigator Class
• Create two routes
First, create two routes to work with. Since this is a basic example, each
route contains only a single button. Tapping the button on the first
route navigates to the second route. Tapping the button on the second
route returns to the first route.
First, set up the visual structure:
First Route
First Route
Second Route
Second Route
Navigate to the Second Route
using Navigator.push()
...
Send Data and Return Among
Screens
• Then use the Navigator in the FirstScreen widget to push a route to
the SecondScreen widget. You put the data that you want to send as a
parameter in its constructor.
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Screen1(text: 'Hello',),
));
WebView in Flutter
You can embed a web browser inside your app using WebView widget. A WebView widget
is a crucial component for many apps that need to display website content without
worrying about using Android or iOS native views
Incorporating the WebView plug-in into your app is extremely simple. WebView widget is
just
like any other widget in Flutter
you can add the following WebView widget to display Android ATC web site content in
your app interface. By default, JavaScript in your WebView widget is disabled, so to
enable it, you should add the javascriptMode property
Example
Navigation and Routing a Pizza Store App
End