์ง๋ ์๊ฐ Container์ ์ด์ด ์ค๋์ Column, Row, Expanded์ ์์๋ณด๋ ค๊ณ ํ๋ค. ์ด์ ํฌ์คํ ์์ ๋ถ๊ฐ๋ฅํ๋ Container ๊ฐ์ ๋ถ๋ฆฌ๋ฅผ ์ด๋ฌํ ์์ ฏ๋ค์ ์ด์ฉํ์ฌ ํด๊ฒฐํ ์ ์๋ค.
https://codekodo.tistory.com/95
3. Container, Padding
์ค๋ ์์๋ณผ ๊ฒ์ Container์ Padding ์์ ฏ์ด๋ค. ๊ฐ์ด ๋ฌถ์ด์ ์์ฑํ๋ ์ด์ ๋ ๋ ์์ ฏ์ด ๊ฑฐ์ ์ ์ฌํ๊ธฐ ๋๋ฌธ์ด๋ค. Container ์ฐ์ ๊ณต์๋ฌธ์์๋ Container๊ฐ ์์ ์์ ฏ์ ์ปค์คํฐ๋ง์ด์ง ํ ์ ์๋ ์์ ฏ์ด
codekodo.tistory.com
์ค๋ ์์๋ณผ ๊ฒ์ Container์ Padding ์์ ฏ์ด๋ค. ๊ฐ์ด ๋ฌถ์ด์ ์์ฑํ๋ ์ด์ ๋ ๋ ์์ ฏ์ด ๊ฑฐ์ ์ ์ฌํ๊ธฐ ๋๋ฌธ์ด๋ค. ์ฐ์ ๊ณต์๋ฌธ์์๋ Container๊ฐ ์์ ์์ ฏ์ ์ปค์คํฐ๋ง์ด์ง ํ ์ ์๋ ์์ ฏ์ด๋ผ๊ณ ๋์์๋ค.
Column
Column์ ์์ง ๋ฐฉํฅ์ผ๋ก element๋ฅผ ๋ณด์ฌ์ฃผ๋ ์์ ฏ์ด๋ค. Column๋ ๋ค์ํ ์์ฑ์ ๊ฐ์ง๊ณ ์๋ค.
Column Column({
Key? key,
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
MainAxisSize mainAxisSize = MainAxisSize.max,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
TextDirection? textDirection,
VerticalDirection verticalDirection = VerticalDirection.down,
TextBaseline? textBaseline,
List<Widget> children = const <Widget>[]
})
์์ฑ๋ค์ ์ค์ ๋ก ์ฝ๋๋ฅผ ์์ฑํด๋ณด๋ฉด์ ์์๋ณด์. ์ฐ์ mainAxisAlignment์ crossAxisAlignment๊ฐ ์ ๋ ฌ์ ๊ดํ ์์ฑ์ด๋ค. Column์ ๊ฒฝ์ฐ main์ ์์ง๋ฐฉํฅ์ผ๋ก ์ ๋ ฌ, crossAxisAlignment๋ ์ํ๋ฐฉํฅ์ผ๋ก์ ์ ๋ ฌ์ ์๋ฏธํ๋ค. verticalDirection์ Column์ ์์๋ค์ ๋ฐฐ์น์ ๋ํ ์ต์ ์ด๋ค.
import 'package:flutter/material.dart';
void main() {
return runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Column ์์ "),
),
body: Column(
verticalDirection: VerticalDirection.up,
children: <Widget>[
Container(
height: 100,
color: Colors.red,
),
Container(
height: 100,
color: Colors.blue,
),
Container(
height: 100,
color: Colors.green,
),
],
),
),
);
}
}
์ด๋ ๊ฒ ์ฝ๋๋ฅผ ์์ฑํ๊ณ ๋น๋๋ฅผ ์งํํ๋ฉด Container๋ผ๋ฆฌ ๊ฒน์น์ง ์๊ณ ์ง๋ ์๊ฐ์ ์ฐ๋ฆฌ๊ฐ ์ํ๋ ์ถ๋ ฅ ๊ฒฐ๊ณผ๊ฐ ๋์ค๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
Column์ ์ ๋ ฌ์๋ ๋ ๊ฐ์ง ํ์ ์ด ์กด์ฌํ๋๋ฐ ์ํ ๋ฐฉํฅ๊ณผ ์์ง ๋ฐฉํฅ์ด๋ค. ์ํ ๋ฐฉํฅ์ CrossAxisAlignment, ์์ง ๋ฐฉํฅ์ MainAxisAlignment์ด๋ค. ์ ๋ ฌ ์์ฑ์๋ ์ฌ๋ฌ ๊ฐ์ง๊ฐ ์กด์ฌํ๋๋ฐ ์์ฃผ ์ฐ์ด๋ spaceAround, spaceBetween, spaceEvenly์ ๋ณด๋ฉด spaceAround์ ๊ฒฝ์ฐ Column์ children์ ์์ ฏ์ ์ค์ฌ์ผ๋ก ์์ชฝ์ ๊ฐ์ ์ฌ๋ฐฑ์ ์ฃผ๋ ์์ฑ์ด๋ค. spaceBetween์ ๊ฒฝ์ฐ ์์ ฏ๋ค ์ฌ์ด์ ๊ฐ์ ์ฌ๋ฐฑ์, spaceEvenly๋ ๋ชจ๋ ์ฌ๋ฐฑ์ด ๊ฐ์ ํฌ๊ธฐ์ธ ์์ฑ์ด๋ค. ์ค์ ์ถ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ์ฝ๊ฒ ์ดํด๊ฐ ๋ ๊ฒ์ด๋ค.
VerticalDirection ์์ฑ์ ๋ง ๊ทธ๋๋ก ์์์ ์๋๋ก ๋ณด์ฌ์ค ๊ฒ์ธ์ง, ์๋์์ ์๋ก ๋ณด์ฌ์ค ๊ฒ์ธ์ง๋ฅผ ์ ํ๋ ์์ฑ์ด๋ค.
Row
Row๋ Column๊ณผ ์ ์ฌํ๋ค. ์ฐจ์ด๊ฐ ์๋ค๋ฉด MainAxisAlignment์ CrossAxisAlignment๊ฐ ์๋ฏธํ๋๊ฒ Column๊ณผ ๋ฐ๋๋ค. Column์์๋ Main์ ์์ง ๋ฐฉํฅ, Cross๋ ์ํ ๋ฐฉํฅ์ด์๋๋ฐ Row์์๋ Main์ ์ํ ๋ฐฉํฅ, Cross๋ ์์ง ๋ฐฉํฅ์ด ๋๋ค.
์์ธํ ์ค๋ช ์ ์๋ตํ๋ ๊ฑธ๋ก...
Expanded
Expanded๋ ๋ญ๊น? ํด์ํ๋ฉด ํ์ฅ? ์ ์๋ฏธ์ธ๋ฐ ์ด๋์ ์ฌ์ฉํ๋ ๊ฒ์ผ๊น? Expanded๋ Column๊ณผ Row์์ ์ฌ์ฉํ ์ ์๋ ์์ ฏ์ผ๋ก ํ์ฅ ๊ฐ๋ฅํ Container๋ผ๊ณ ์๊ฐํ๋ฉด ํธํ๋ค. ์๋์ ๋ ์ถ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ์ฒซ ๋ฒ์งธ๋ Expanded๋ฅผ ์ฌ์ฉํ์ง ์์ ๊ฒฐ๊ณผ์ด๊ณ , ๋ ๋ฒ์งธ๋ Expaned๋ฅผ ์ฌ์ฉํ ๊ฒฐ๊ณผ์ด๋ค.
Expanded๋ฅผ ์ฌ์ฉํ๋ฉด ์ฌ๋ฐฑ ์์ด ์ ์ฐํ๊ฒ Container๋ฅผ ์ฑ์ธ ์ ์๋ค. ๋ํ Expanded์๋ flex๋ผ๋ ์์ฑ์ด ์กด์ฌํ๋๋ฐ ์ด๋ Expanded ๊ฐ์ ํฌ๊ธฐ๋ฅผ ์๋ฏธํ๋ค.
์ด๋ ๊ฒ ์ฌ์ฉํ ์ ์๊ณ Black : Indigo Container์ ํฌ๊ธฐ๊ฐ 1 : 2 ๊ฐ ๋๋ค.
๊ฒ์์ ์์ญ์ ํฌ๊ธฐ๊ฐ ์ข ๋ ์ปค์ง ๊ฒ์ ๋ณผ ์ ์๋ค.
'๐ป ๊ฐ๋ฐ > Flutter' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Flutter / Dart] What is Singleton? (0) | 2022.07.21 |
---|---|
[Flutter] SingleChildScrollView, ListView, ListView.bulider (1) | 2021.08.18 |
3. Container, Padding (0) | 2021.08.18 |
2. Stateless, Stateful (0) | 2021.07.13 |
1. Widget (0) | 2021.07.13 |