Unit 2 - 3 - User Interface Design and Navigation
Unit 2 - 3 - User Interface Design and Navigation
• Introduction to widgets
• Stateless and Stateful widgets
• Basic Widgets (Text, Image, container, Elevated Button etc.)
• Building layouts using Row and Column widgets
• Designing Responsive Layouts
WHAT IS WIDGETS?
• Async:
• Provides async functionality in the flutter application.
• Cupertino:
• iOS designed widgets
CUPERTINO WIDGETS
• Input:
• Provides input functionality
• Interaction Models:
• Manage touch events and route users to different views in the
application
• Layout:
• Helps in placing the other widgets on the screen as needed.
CONT..
Layout Widgets:
• Container:
• A rectangular box decorated using BoxDecoration widgets with
background, border and shadow.
• Center:
• Center its child widget
• Row:
• Arrange children in the horizontal direction
CONT..
• Column:
• Arrange children in vertical direction
• Stack:
• Arrange one above the another
CONT..
• Can have only one child but that child can have many subchilds.
• Properties:
• Height
• Width
• Color
• Child
• Padding
• Alignment
• Decoration
• Margin etc..
CENTER WIDGET
• Textalignment
• textdirection
• Style Attributes:
• fontSize
• Color
• fontWeight
• backgroundColor
BUTTONS
TextButton(
onPressed: () {},
child: const Text(
'Flat Button',
style: TextStyle(color: Colors.white, fontSize: 13.0),
),
• )
ELEVATED BUTTON
• These are simple buttons with text in the center enclosed by a thin border.
You can modify the styling of these buttons by using properties provided in
the material package. They have a slight elevation.
OutlinedButton(
child: Text(
"Outlined Button",
style: TextStyle(
color: Colors.green,
),
),
onPressed: () {},
),
INKWELL
• Row
• We can control how a row widget aligns its children based on
our choice using the property crossAxisAlignment and
mainAxisAlignment. The row's cross-axis will run vertically, and
the main axis will run horizontally.
ALIGNMENT OF CHILDREN WIDGETS
IN ROW
• start: It will place the children from the starting of the main
axis.
• end: It will place the children at the end of the main axis.
• center: It will place the children in the middle of the main axis.
• spaceBetween: It will place the free space between the
children evenly.
• spaceAround: It will place the free space between the
children evenly and half of that space before and after the first
and last children widget.
• spaceEvenly: It will place the free space between the children
evenly and before and after the first and last children widget.
CONT..
• Column
• The column's cross-axis will run horizontally, and the main axis
will run vertically.
DRAWBACKS OF ROW AND COLUMN
WIDGET
body: Center(
child: ElevatedButton(
onPressed: () {
// Navigate to a new page here
},
child: Text('Go to New Page'),
),
),
SETTING UP NAVIGATION
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
}
CONT..
• Using Navigator.push()
• Navigator.push takes two arguments: context and a Route object.
• context is a BuildContext that Flutter uses to locate the Navigator in
the widget tree.
• We create a MaterialPageRoute and specify the builder function,
which returns the widget to be displayed on the new page.
BASIC NAVIGATION TECHNIQUES
• ListView
• ListView.Builder
• ListView.Seperated
• ListTile
• RadioButtonListTile
• CheckboxListTile
• DropDownButton
• DateTimePickers
• CircleAvatar
• FloatActionButton
SHARED PREFERENCES
• In pubspec.yaml file
dependencies:
shared_preferences: ^latest_version
After adding the dependency, run the following command to get the
package:
flutter pub get
The next step involves initializing SharedPreferences. This is typically done
in the main function or within the initState method of a stateful widget.
The initialization process consists in calling
SharedPreferences.getInstance(), an asynchronous operation.
BEST PRACTICES