
class MyText extends StatelessWidget {
Widget build(BuildContext context) {
return Text('나는 Stateless 위젯!');
}
}
setState()를 사용해 상태를 갱신해야 화면이 업데이트된다.class CounterWidget extends StatefulWidget {
_CounterWidgetState createState() => _CounterWidgetState();
}
class _CounterWidgetState extends State<CounterWidget> {
int counter = 0;
void _increment() {
setState(() {
counter++;
});
}
Widget build(BuildContext context) {
return Column(
children: [
Text('카운터: $counter'),
ElevatedButton(
onPressed: _increment,
child: Text('증가하기'),
),
],
);
}
}

Scaffold(
appBar: AppBar(title: Text('앱 타이틀')),
body: Center(child: Text('여기는 본문 영역')),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
)
appBar,body,drawer,bottomNavigationBar등 다양한 영역을 정의할 수 있다.

| 속성 | 설명 | 예시 코드 |
|---|---|---|
appBar | 상단 앱 바 영역 | AppBar(title: Text('제목')) |
body | 메인 콘텐츠 영역 | Center(child: Text('본문')) |
floatingActionButton | 오른쪽 하단 플로팅 버튼 | FloatingActionButton(...) |
drawer | 좌측 사이드 메뉴 (햄버거 메뉴) | Drawer(child: ListView(...)) |
endDrawer | 우측 사이드 메뉴 | Drawer(...) |
bottomNavigationBar | 하단 탭 메뉴 | BottomNavigationBar(...) |
bottomSheet | 하단 고정 시트 | Container(height: 60, child: Text(...)) |
backgroundColor | Scaffold 배경 색상 | backgroundColor: Colors.grey[100] |
persistentFooterButtons | 하단 고정 버튼 리스트 | persistentFooterButtons: [Button(...)] |
Text('안녕하세요!', style: TextStyle(fontSize: 20))
Container(
width: 100,
height: 50,
color: Colors.amber,
child: Text('박스'),
)
Image.asset('assets/logo.png')
Image.network('https://flutter.dev/images/flutter-logo-sharing.png')
Icon(Icons.favorite, color: Colors.red)
ElevatedButton(onPressed: () {}, child: Text('클릭'))
TextField(decoration: InputDecoration(labelText: '입력하세요'))
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [Text('A'), Text('B'), Text('C')],
)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [Text('첫 번째'), Text('두 번째')],
)
Padding(
padding: EdgeInsets.all(16.0),
child: Text('패딩이 들어간 텍스트'),
)
SizedBox(width: 20, height: 50)
여백을 주거나 크기를 지정할 때 사용
Row(
children: [
Expanded(child: Container(color: Colors.red)),
Expanded(child: Container(color: Colors.blue)),
],
)
남은 공간을 위젯 간에 비율로 배분
Align(alignment: Alignment.bottomRight, child: Text('오른쪽 아래'))
Center(child: Text('가운데'))
Stack(
children: [
Container(width: 200, height: 200, color: Colors.green),
Positioned(top: 50, left: 50, child: Text('겹친 텍스트')),
],
)
위젯을 겹쳐서 배치할 수 있음
ListView(
children: [
ListTile(title: Text('항목 1')),
ListTile(title: Text('항목 2')),
],
)
GridView.count(
crossAxisCount: 2,
children: List.generate(4, (index) => Text('아이템 $index')),
)
GestureDetector(
onTap: () {
print('탭됨!');
},
child: Container(color: Colors.blue, child: Text('탭해보세요')),
)
| 카테고리 | 대표 위젯 |
|---|---|
| 텍스트 | Text, TextField |
| 이미지 | Image.asset, Image.network |
| 버튼 | ElevatedButton, IconButton |
| 입력폼 | TextField, Form, Checkbox |
| 레이아웃 | Row, Column, Expanded, Stack, Padding, Align |
| 기타 | Scaffold, ListView, GridView, GestureDetector |
정리가 진짜 깔끔하게 잘되어있네요 ㅎㅎ