EdgeInsets
- Flutter course
- Beginner
- Lesson 37/99
- 4 min
Learn the difference between EdgeInsets.all, only and symmetric.
EdgeInsets
EdgeInsets is the object that defines the spacing amount for Padding and margin. It offers three main constructors: all gives the same value to all four sides, only gives values to specific sides, and symmetric takes separate values for horizontal and vertical.
// All four sides 16
EdgeInsets.all(16.0)
// Only left and right 8
EdgeInsets.only(left: 8, right: 8)
// Horizontal 12, vertical 6
EdgeInsets.symmetric(horizontal: 12, vertical: 6)all, only, symmetric difference
all(d) gives d to all sides; the simplest option. only(left, top, right, bottom) gives values only to specified sides; unspecified ones stay 0. symmetric(horizontal, vertical) gives separate values for horizontal (left+right) and vertical (top+bottom).
Padding(
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
child: Text('Simetrik'),
)
Padding(
padding: EdgeInsets.only(bottom: 30),
child: Text('Alt boşluk'),
)Practice Print EdgeInsets info
In main, print two lines with print: all dort kenar and symmetric yatay dikey.
Starter code
void main() {
// iki satır yazdır:
// all dort kenar
// symmetric yatay dikey
}Sample solution
void main() {
print('all dort kenar');
print('symmetric yatay dikey');
}Expected output
all dort kenar symmetric yatay dikey
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does EdgeInsets.symmetric take?
- An empty value
- Separate values for horizontal and vertical Correct answer
- A single value to all four sides
- Values for specific sides
Explanation: symmetric takes separate values for horizontal (left+right) and vertical (top+bottom).
2 Separate horizontal and vertical
padding: EdgeInsets.____(horizontal: 20, vertical: 10),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
Explanation: The symmetric constructor takes separate values for horizontal and vertical.
3 EdgeInsets concepts
| Term | Meaning |
|---|---|
EdgeInsets.all |
Same value to all four sides |
EdgeInsets.only |
Values to specific sides |
EdgeInsets.symmetric |
Separate horizontal and vertical |
kurucu seçimi |
Based on spacing pattern |