Flutter에서 버튼은 크게 두 가지로 나뉨:
👉 1) 기본 제공 버튼
👉 2) 커스텀 클릭 처리 (InkWell 등)
| 버튼 | 설명 |
|---|---|
| ElevatedButton | 가장 기본 (튀어나온 버튼) |
| TextButton | 텍스트만 있는 버튼 |
| OutlinedButton | 테두리 버튼 |
| IconButton | 아이콘 클릭 |
| FloatingActionButton | 떠 있는 주요 버튼 |
ElevatedButton(
onPressed: () {
print("클릭!");
},
child: const Text("Elevated 버튼"),
)
👉 가장 많이 사용 (주요 액션)
TextButton(
onPressed: () {},
child: const Text("Text 버튼"),
)
👉 가벼운 액션 (취소, 보조 버튼)
OutlinedButton(
onPressed: () {},
child: const Text("Outlined 버튼"),
)
👉 중간 강조 버튼
IconButton(
onPressed: () {},
icon: const Icon(Icons.favorite),
)
👉 아이콘 클릭용
FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.add),
)
👉 화면 하단 핵심 액션 (+ 버튼)
👉 버튼이 아니라 “클릭 효과 + 터치 감지 위젯”
👉 어떤 UI든 클릭 가능하게 만듦
InkWell(
onTap: () {
print("클릭됨");
},
child: Container(
padding: const EdgeInsets.all(16),
color: Colors.blue,
child: const Text("클릭 영역"),
),
)
InkWell(
onTap: () {
print("상품 클릭");
},
child: Row(
children: [
Container(width: 50, height: 50, color: Colors.grey),
const SizedBox(width: 10),
const Text("상품 이름"),
],
),
)
👉 리스트 전체 클릭 가능
👉 Material 위젯 안에서 사용해야 ripple 효과 보임
Material(
child: InkWell(
onTap: () {},
child: Container(
padding: const EdgeInsets.all(16),
child: const Text("Ripple OK"),
),
),
)
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
Widget build(BuildContext context) {
return const MaterialApp(
home: ButtonExample(),
);
}
}
class ButtonExample extends StatelessWidget {
const ButtonExample({super.key});
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Button Example")),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.add),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {},
child: const Text("Elevated"),
),
TextButton(
onPressed: () {},
child: const Text("Text"),
),
OutlinedButton(
onPressed: () {},
child: const Text("Outlined"),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.favorite),
),
const SizedBox(height: 20),
// InkWell 예제
Material(
child: InkWell(
onTap: () {
print("InkWell 클릭");
},
child: Container(
padding: const EdgeInsets.all(16),
color: Colors.orange,
child: const Text("InkWell 버튼"),
),
),
),
],
),
);
}
}
| 구분 | 역할 |
|---|---|
| ElevatedButton | 주요 액션 |
| TextButton | 보조 액션 |
| OutlinedButton | 중간 강조 |
| IconButton | 아이콘 |
| FAB | 핵심 버튼 |
| InkWell | 커스텀 클릭 영역 |
👉 기본 버튼 + InkWell 조합이면 모든 UI 구현 가능
👉 쉽게 말하면
“UI가 그려지는 종이” 같은 존재
Flutter의 InkWell 같은 위젯은
👉 Material 위에서만 ripple(물결 효과)을 그릴 수 있음
InkWell(
onTap: () {},
child: Container(
color: Colors.orange,
padding: EdgeInsets.all(16),
child: Text("버튼"),
),
)
👉 ripple 효과 안 보일 수 있음
Material(
child: InkWell(
onTap: () {},
child: Container(
color: Colors.orange,
padding: EdgeInsets.all(16),
child: Text("버튼"),
),
),
)
👉 클릭 시 ripple 효과 정상 표시
Material (표면)
└─ InkWell (터치 감지 + ripple)
└─ UI (Container 등)
👉 InkWell은 Material 위에 “잉크 효과”를 그림
| 기능 | 설명 |
|---|---|
| ripple 효과 | 터치 시 물결 애니메이션 |
| elevation | 그림자 (떠 있는 느낌) |
| color | 배경색 |
| shape | 모양 (둥근 모서리 등) |
Material(
color: Colors.blue,
elevation: 4,
borderRadius: BorderRadius.circular(10),
child: InkWell(
borderRadius: BorderRadius.circular(10),
onTap: () {},
child: Padding(
padding: EdgeInsets.all(16),
child: Text(
"Material 버튼",
style: TextStyle(color: Colors.white),
),
),
),
)
👉 버튼처럼 보이는 커스텀 UI
👉 아래 상황에서 직접 사용:
👉 Flutter 기본 구조:
MaterialApp
└─ Scaffold
└─ AppBar / body
👉 대부분 자동으로 Material 포함됨
그래서:
ElevatedButton(...)
👉 따로 Material 안 써도 됨
| 개념 | 설명 |
|---|---|
| Material | UI 표면 |
| InkWell | 클릭 + ripple |
| 관계 | Material 위에서 InkWell 동작 |
👉 Material은 ripple 효과가 그려지는 “배경”이다