Chapter 3
Chapter 3
ElevatedButton
OutlinedButton
TextButton
IconButton
FloatingActionButton
body: Center(
child: ElevatedButton(
class MyApp extends StatelessWidget { onPressed: () {
@override // Add your onPressed functionality here
Widget build(BuildContext context) { print('Button pressed');
return MaterialApp( },
home: Scaffold( child: Text('ElevatedButton'),
appBar: AppBar( ),
title: Text('ElevatedButton Example'), ),
), ),
);
}
}
MOBILE APPLICATION DEVELOPMENT 33
Button: OutlinedButton
body: Center(
child: OutlinedButton(
@override child: Text("Tap on this"),
Widget build(BuildContext context) { style: OutlinedButton.styleFrom(
return Scaffold( primary: Colors.red,
appBar: AppBar( side: BorderSide(
title: Text("AppMaking.co"), color: Colors.red,
centerTitle: true, ),
backgroundColor: Colors.blue[900], ),
), onPressed: () {},
),
),
);
MOBILE APPLICATION DEVELOPMENT 34
}
Button: TextButton
body: Center(
child: TextButton(
class MyApp extends StatelessWidget { onPressed: () {
@override // Add your onPressed functionality here
Widget build(BuildContext context) { print('Button pressed');
return MaterialApp( },
home: Scaffold( child: Text('TextButton'),
appBar: AppBar( ),
title: Text('TextButton Example'), ),
), ),
);
}
}
MOBILE APPLICATION DEVELOPMENT 35
Reading Assignment
IconButton
Floating Action
Container: The Container widget is a versatile widget that can contain other widgets and
provides properties for layout, padding, margin, decoration, and more. It's commonly used
to create spacing between widgets, apply background colors, or add borders.
Row and Column: These widgets are used to arrange child widgets in a horizontal (Row) or
vertical (Column) direction. They can contain multiple children and provide properties for
controlling alignment, spacing, and flexibility.
Stack: The Stack widget is used to overlay multiple widgets on top of each other. Widgets
in a Stack are positioned relative to each other or relative to the Stack itself. This is useful for
creating complex layouts where widgets need to overlap.
ListView: The ListView widget is used to create a scrollable list of children. It's commonly
used when you have a large number of children that need to be scrolled vertically or
horizontally.
GridView: Similar to ListView, the GridView widget is used to create a scrollable grid of children. It's
useful for displaying items in a grid layout, where each item can have a fixed or flexible size.
Spacer: The Spacer widget is used to create flexible space within a Row or Column. It expands to fill
the available space along the main axis and can be used to distribute space evenly between widgets.
Expanded: The Expanded widget is used to make a child widget expand to fill the available space
along the main axis of its parent Row, Column, or Flex widget. It's commonly used in combination
with Row or Column to create flexible layouts.
Flexible: Similar to Expanded, the Flexible widget is used to make a child widget flexible within its
parent's constraints. However, unlike Expanded, it allows the child to grow or shrink based on its flex
factor.
ListView(
children: <Widget>[
ListTile(title: Text('Item 1')),
ListTile(title: Text('Item 2')),
ListTile(title: Text('Item 3')),
// Add more list items as needed
],
)
Row(
children: <Widget>[
Container(color: Colors.red, width: 50, height: 50),
Flexible(
flex: 2,
child: Container(color: Colors.blue),
),
Container(color: Colors.green, width: 50, height: 50),
],
)
Stack( Positioned(
top: 50,
children: <Widget>[ left: 50,
Container( child: Container(
width: 100,
width: 200, height: 100,
height: 200, color: Colors.red,
),
color: Colors.blue, ),
), ],
)
Row(
children: <Widget>[
Container(width: 50, height: 50, color: Colors.red),
Spacer(),
Container(width: 50, height: 50, color: Colors.blue),
Spacer(),
Container(width: 50, height: 50, color: Colors.green),
],
)