플러터:테마: 두 판 사이의 차이
보이기
잔글편집 요약 없음 |
|||
| 2번째 줄: | 2번째 줄: | ||
== 개요 == | == 개요 == | ||
* 색이나 이런저런 설정을 한번에 변화시키기 위해 테마를 사용한다. | |||
* 앱 전체에 적용되는 색상, 폰트, 버튼 스타일 등의 시각적 요소를 일관되게 관리하기 위한 시스템. | |||
* Material Design 철학을 기반으로, 위젯 단위가 아닌 앱 단위 스타일 관리. | |||
=== 장점 === | |||
* UI 일관성 유지(당연하지만, 규모가 커질수록 용이해진다.) | |||
* 스타일 변경 시 코드 수정 최소화 | |||
* 다크 모드 / 라이트 모드 대응 용이 | |||
= 기본 구조 = | |||
Flutter 앱은 일반적으로 <code>MaterialApp</code> 위젯을 루트로 가지며, 이곳에서 Theme를 정의한다.<syntaxhighlight lang="dart"> | |||
MaterialApp( | |||
theme: ThemeData( | |||
primaryColor: Colors.blue, | |||
), | |||
home: MyHomePage(), | |||
); | |||
</syntaxhighlight> | |||
== | == ColorScheme == | ||
Flutter에서는 개별 색상보다 ColorScheme 사용을 권장.<syntaxhighlight lang="dart"> | |||
ThemeData( | |||
colorScheme: ColorScheme.fromSeed( | |||
seedColor: Colors.teal, | |||
brightness: Brightness.light, | |||
), | |||
); | |||
</syntaxhighlight>주요 색상 구성: | |||
* primary | |||
* secondary | |||
* background | |||
* surface | |||
* error | |||
== TextTheme == | |||
앱 전체 텍스트 스타일을 정의한다.<syntaxhighlight lang="dart"> | |||
ThemeData( | |||
textTheme: TextTheme( | |||
bodyLarge: TextStyle(fontSize: 18), | |||
titleLarge: TextStyle(fontWeight: FontWeight.bold), | |||
), | |||
); | |||
</syntaxhighlight>자주 사용하는 텍스트 스타일: | |||
* bodySmall / bodyMedium / bodyLarge | |||
* titleSmall / titleMedium / titleLarge | |||
* headlineSmall / headlineMedium / headlineLarge | |||
== Button Theme == | |||
Flutter 2.0 이후 버튼은 다음 세 가지로 통합되었다. | |||
* ElevatedButton | |||
* TextButton | |||
* OutlinedButton | |||
각 버튼은 개별 스타일을 테마에서 정의할 수 있다. | |||
=== ElevatedButton Theme === | |||
<syntaxhighlight lang="dart"> | |||
ThemeData( | |||
elevatedButtonTheme: ElevatedButtonThemeData( | |||
style: ElevatedButton.styleFrom( | |||
backgroundColor: Colors.blue, | |||
foregroundColor: Colors.white, | |||
), | |||
), | |||
); | |||
</syntaxhighlight> | |||
=== TextButton Theme === | |||
<syntaxhighlight lang="dart"> | |||
ThemeData( | |||
textButtonTheme: TextButtonThemeData( | |||
style: TextButton.styleFrom( | |||
foregroundColor: Colors.blue, | |||
), | |||
), | |||
); | |||
</syntaxhighlight> | |||
== Theme.of(context) == | |||
위젯 내부에서 현재 테마에 접근할 때 사용한다.<syntaxhighlight lang="dart"> | |||
final theme = Theme.of(context); | |||
Text( | |||
'Hello', | |||
style: theme.textTheme.bodyLarge, | |||
); | |||
</syntaxhighlight> | |||
== 다크 모드 == | |||
Flutter는 라이트 / 다크 테마를 동시에 정의할 수 있다.<syntaxhighlight lang="dart"> | |||
MaterialApp( | |||
theme: ThemeData.light(), | |||
darkTheme: ThemeData.dark(), | |||
themeMode: ThemeMode.system, // 시스템 설정을 따라 다크테마 지정 결정. | |||
); | |||
</syntaxhighlight>themeMode 옵션 | |||
* ThemeMode.light | |||
* ThemeMode.dark | |||
* ThemeMode.system | |||
== Material 3 == | |||
Flutter 최신 버전에서는 Material 3 사용이 권장된다.<syntaxhighlight lang="dart"> | |||
ThemeData( | |||
useMaterial3: true, | |||
); | |||
</syntaxhighlight>Material 3 특징: | |||
* 둥근 모서리 | |||
* 색상 자동 조합 | |||
동적인 컬러 시스템 | |||
2026년 1월 7일 (수) 12:30 판
- 플러터:개요
- 플러터:실행
- 플러터:개념 잡기
- 권한 사용
- 위젯
- 플러터:DB연결
- 플러터:Firebase(미완)
- 플러터:MySQL(미완)
- 디자인
- 플러터:배포
- 플러터:배포(안드로이드)(미완)
- 플러터:참고자료
- 플러터:위젯
- 플러터:구글 AdMob(미완)
- 플러터:라이브러리
개요
- 색이나 이런저런 설정을 한번에 변화시키기 위해 테마를 사용한다.
- 앱 전체에 적용되는 색상, 폰트, 버튼 스타일 등의 시각적 요소를 일관되게 관리하기 위한 시스템.
- Material Design 철학을 기반으로, 위젯 단위가 아닌 앱 단위 스타일 관리.
장점
- UI 일관성 유지(당연하지만, 규모가 커질수록 용이해진다.)
- 스타일 변경 시 코드 수정 최소화
- 다크 모드 / 라이트 모드 대응 용이
기본 구조
Flutter 앱은 일반적으로 MaterialApp 위젯을 루트로 가지며, 이곳에서 Theme를 정의한다.
MaterialApp(
theme: ThemeData(
primaryColor: Colors.blue,
),
home: MyHomePage(),
);
ColorScheme
Flutter에서는 개별 색상보다 ColorScheme 사용을 권장.
ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.teal,
brightness: Brightness.light,
),
);
주요 색상 구성:
- primary
- secondary
- background
- surface
- error
TextTheme
앱 전체 텍스트 스타일을 정의한다.
ThemeData(
textTheme: TextTheme(
bodyLarge: TextStyle(fontSize: 18),
titleLarge: TextStyle(fontWeight: FontWeight.bold),
),
);
자주 사용하는 텍스트 스타일:
- bodySmall / bodyMedium / bodyLarge
- titleSmall / titleMedium / titleLarge
- headlineSmall / headlineMedium / headlineLarge
Button Theme
Flutter 2.0 이후 버튼은 다음 세 가지로 통합되었다.
- ElevatedButton
- TextButton
- OutlinedButton
각 버튼은 개별 스타일을 테마에서 정의할 수 있다.
ElevatedButton Theme
ThemeData(
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
),
);
TextButton Theme
ThemeData(
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Colors.blue,
),
),
);
Theme.of(context)
위젯 내부에서 현재 테마에 접근할 때 사용한다.
final theme = Theme.of(context);
Text(
'Hello',
style: theme.textTheme.bodyLarge,
);
다크 모드
Flutter는 라이트 / 다크 테마를 동시에 정의할 수 있다.
MaterialApp(
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system, // 시스템 설정을 따라 다크테마 지정 결정.
);
themeMode 옵션
- ThemeMode.light
- ThemeMode.dark
- ThemeMode.system
Material 3
Flutter 최신 버전에서는 Material 3 사용이 권장된다.
ThemeData(
useMaterial3: true,
);
Material 3 특징:
- 둥근 모서리
- 색상 자동 조합
동적인 컬러 시스템