반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 디프만16기
- Kotlin
- kakao
- nGrinder
- c
- 운영체제
- 코드 트리
- Spring
- Sharding
- 디프만
- pub.dev
- 코딩
- OAuth
- depromeet
- Scaffold
- 부하 테스트
- java
- Oidc
- 코드트리
- dip
- C언어
- 코딩 테스트
- Redis
- flutter
- exception
- AOP
- Kafka
- 코딩테스트
- 자료구조
- 연습문제
Archives
- Today
- Total
Nick Dev
[Flutter] 06. Flutter Theme 본문
반응형
- Theme 관련 코드는 실무 시 따로 디렉토리 만들어서 관리하는 것이 유지 보수에 좋다
1. ThemeData
: Material Design Theme에 대한 색상 및 Typography 값을 정의하고 보유하는 클래스
- colorScheme
- 앱의 전반적인 색의 theme을 정해 간편하게 디자인 가능
- 간편한 방식 2가지
- ColorScheme.light() or .dark()
- ColorScheme.fromSeed ( ... )
- textScheme
- 앱 전반적으로 사용할 수 있는 다양한 스타일의 텍스를 캡슐화하는 인터페이스
- bodyMedium, Large 등 정의해놓고 이후에 Text Widget에서 style에서 선언해 사용 가능
- useMaterial3
- useMaterial3: true
- 앱이 Material3로 디자인된다
- useMaterial3: true
2. ColorScheme.light( ... ) or dark (... )
// theme.dart
final customTheme = ThemeData(
colorScheme: const ColorScheme.light(
primary: Colors.indigo,
secondary: Colors.green,
tertiary: Colors.yellow,
),
textTheme: const TextTheme(
bodyMedium: TextStyle(fontWeight: FontWeight.normal, fontSize: 30),
),
);
- primary
- theme의 원색을 indigo로 설정
- primary에 선언된 색은 앱의 화면과 구성요소에서 자주 사용됨
- secondary
- theme의 보조 색상을 green으로 설정
- secondary에 선언된 색은 UI의 일부를 강조
- tertiary
- theme의 3차 색상을 yellow로 설정
- 현재 Material 2 Design을 따르고 있음
3. ColorScheme.fromSeed( ... )
// theme.dart
final customTheme = ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
textTheme: const TextTheme(
bodyLarge: TextStyle(fontWeight: FontWeight.normal, fontSize: 30),
),
useMaterial3: true,
);
- fromSeed
- 단일 시드 색상에서 대비되는 색상 쌍의 전체 세트를 생성
- 변수로 넣은 seedColor로 표면, 배경, 오류 등 기본 및 보조 색상 생성하는데 사용된다
- 현재 이 사진은 Material 3 Desgin으로 설정
4. textTheme
@override
Widget build(BuildContext context) {
// 위에서 설정한 bodyLarge를 가져오려면 theme data를 가져와야함
// final textTheme = Theme.of(context).textTheme;
final textTheme = customTheme.textTheme;
return Scaffold(
appBar: AppBar(
title: const Text('Flutter Theme'),
centerTitle: true,
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Press Count', style: textTheme.bodyMedium,),
Text('$count', style: textTheme.displayLarge,),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => setState(() => count++),
),
);
}
- theme.dart 파일에서 정의한 textTheme를 가져오려면 변수로 선언해서 사용해야함
- 만약 main.dart 파일에서 theme를 정의한 경우, 위 코드에서 주석처리된 부분처럼
- final textTheme = Theme.of(context).textTheme;
- 이렇게 변수 선언한 후
- Text Widget의 style 선언 시 사용하면 된다
5. AppBarTheme
- appBar만 따로 theme를 디자인할 수 있음
- backgroundColor를 선언해 앱 바만 색을 변경할 수 있음
반응형
'Flutter' 카테고리의 다른 글
[Flutter] 08. 다국어 지원 및 아이콘 변경하기 (0) | 2023.07.28 |
---|---|
[Flutter] 07. Widget 기능 및 매개변수 정리 (0) | 2023.07.28 |
[Flutter] 05. 페이지 → 페이지 이동하기 (0) | 2023.07.25 |
[Flutter] 04. 외부 라이브러리 가져오기 & 로컬 이미지 파일 사용하기 (pubspec.yaml) (0) | 2023.07.25 |
[Flutter] 03. CallBack (VoidCallback, InkWell, GestureDetector) (0) | 2023.07.24 |