Chapter 06 Handling user input and navigation
Chapter 06 Handling user input and navigation
INPUT AND
NAVIGATION
I CT425 MOBILE APPLICATION DEVELOPMENT
PRASHAYA FUSI RIPONG (PH.D.)
1. Handling buttons for user input
2. Basic Navigation: pushing and
OUTLINE popping routes
3. Navigation widgets: Drawer and
Tab
HANDLING BUTTONS FOR USER INPUT
• 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”),
• All apps have the concept of moving from one screen to another.
• The flutter have four ways of navigating:
Stacks: user taps a button to go through a predefined workflow
History is maintained, and they can travel back one level by hitting a back button
Drawers: Most of the screen shows a widget, but on the left edge
A drawer is peeking out at the user, if pressing one changes the widget in the main part
of screen
Tabs: Some room is reserved for a set of tabs at the top / the bottom of the screen.
User press on a tab, app will show the widget that corresponds to that tab
Dialogs: a model (pop-up windows) that stay until the user dismisses them
STACK NAVIGATION
• Stack navigation is a familiar with queues and
stacks
Examples:
NAVIGATION AND ROUTING
• In any application, navigation from one page / screen to another defines the
work flow of the application
• The way that the navigation of an application is handled is called ‘Routing’
• Flutter provides a basic routing class – ‘MaterialPageRoute’
• There are two methods as
Navigator.push
Navigator.pop
They are to define the work flow of an application
• Navigation.push – is used to transition from the first screen to the second screen
Navigator.push (context)
PUSHING A NEW ROUTE
DefaultTabController(
// total 5 tabs
length: 5,
child:
);
TAB NAVIGATION
• Adding tabs
A tab in Flutter can be created using a ‘TabBar’
widget
home: DefaultTabController(
length: 5,
child: Scaffold(
appBar: AppBar(
bottom: const TabBar(
tabs: [
Tab(icon: Icon(Icons.music_note)),
Tab(icon: Icon(Icons.music_video)),
Tab(icon: Icon(Icons.camera_alt)),
Tab(icon: Icon(Icons.grade)),
Tab(icon: Icon(Icons.email)),
],
), //TabBar
TAB NAVIGATION
• Adding content to tabs
The ‘TabBarView’ widget can be used to specify
the contents of each tab