Basic Widgets in Flutter
Basic Widgets in Flutter
Component of
Flutter Basic Widgets in Flutter
2
Intro to the Counter app
3
Flutter project structure
Writing test.
4
Application entry point and import library
5
The build method
• MyApp is a widget inherited
StatelessWidget.
7
The example
Everything in Flutter is Widget. Use Row and Column elements to create layout structure.
8
Row - MainAxisAlignment
start spaceBetween
center spaceAround
end spaceEvenly
9
Row - CrossAxisAlignment
start end
center stretch
10
Column - MainAxisAlignment
start center end spaceBetween spaceAround spaceEvenly
11
Column - CrossAxisAlignment
start center end stretch
12
Row/Column - MainAxisSize
Row Column
min max
min
max
13
Expanded
14
fl
fl
fl
fl
fl
fl
fl
fl
fl
Wrap
Without Wrap With Wrap
15
Wrap - Horizontal
(spacing)
(runSpacing)
.direction: Axis.horizontal
16
Wrap - Vertical
(spacing)
(runSpacing)
.direction: Axis.vertical
17
18
fi
19
MaterialApp Widget
• It leans on Material style guidelines.
• Provides a ton of bene ts that effect its entire widget sub-tree: Theme, Router,
Localization, Navigator, …
• There is no drawback to using MaterialApp, even if you don’t want to use Material
Design guidelines.
20
fi
Scaffold Widget
•Scaffold is designed to make
applications (that follow Material
guidelines) as easy as possible to build.
21
fi
Text
• A run of text with a single style.
• The style widget is optional to decoration.
Hello, Thea!
How are you feel today?
22
Rich Text
• A run of text with a multiply style.
Hello, Thea!
23
Image
• Several constructors are provided:
• Image.asset(‘assets/image/
dart_lang.png’)
• Image.network(‘https://edu.200lab.io/
dart_lang.png’)
24
fi
fi
ElevatedButton
• A material Design “elevated button”
Click me
25
ElevatedButton.icon
• A material Design “elevated button”
Click me
26
TextButton
Click me
27
2.4 Material and Cupertino
28
What is Material design?
29
What is Cupertino design?
• Clarity
• Depth
• Deference
30
Material vs Cupertino
TabBar CupertinoTapBar
31
Material vs Cupertino
TextField CupertinoTextField
32
Material vs Cupertino
Switch CupertinoSwitch
33
Code time
34
Practice 1: Choice one in two design
35
Challenge
36