1. 개요
MaterialApp은 Flutter 앱의 가장 바깥쪽에서 앱 전체 환경을 설정하는 위젯이다.Flutter에서 Material Design 기반 앱을 만들 때 보통
runApp() 안에 MaterialApp을 넣는다.void main() {
runApp(const MyApp());
}👉
MaterialApp은 화면 하나를 그리는 위젯이라기보다, 앱 전체의 시작 환경을 잡아주는 루트 위젯이다.2. 기본 예제
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: "PatuaOne"),
home: RecipePage(),
);
}
}home에는 앱이 처음 보여줄 화면을 넣는다.MaterialApp └─ RecipePage └─ Scaffold
3. 주요 파라미터
파라미터 | 의미 |
home | 앱이 처음 보여줄 화면 |
title | 앱 제목 |
theme | 앱 전체 테마 설정 |
debugShowCheckedModeBanner | 디버그 배너 표시 여부 |
routes | 이름 기반 화면 이동 설정 |
initialRoute | 처음 시작할 route 이름 |
처음에는
home, theme, debugShowCheckedModeBanner를 가장 자주 사용한다.4. 정리
MaterialApp은 Flutter 앱의 루트 위젯이다.
home에는 처음 보여줄 화면을 넣는다.
theme으로 앱 전체 스타일을 설정할 수 있다.
debugShowCheckedModeBanner로 디버그 배너 표시 여부를 조절할 수 있다.
5. 결론
MaterialApp은 Flutter 앱을 시작하기 위한 가장 바깥쪽 설정 위젯이다.
Share article