원문
https://api.flutter.dev/flutter/material/TextTheme-class.html
apply 와 copyWith를 이전 언어에서도 잘 사용해보지 않아서 차이점을 몰랐다.
이번에 구글에서 제공하는 코드랩을 진행하면서 마주하게되었다.
코드를 보고나니 정리할 필요가 있다고 생각되어 작성한다.
예시 코드는 아래와 같다.
공식 문서의 Methods에서 확인해보면
apply({String? fontFamily, double fontSizeFactor = 1.0, double fontSizeDelta = 0.0, Color? displayColor, Color? bodyColor, TextDecoration? decoration, Color? decorationColor, TextDecorationStyle? decorationStyle}) → TextThemeCreates a copy of this text theme but with the given field replaced in each of the individual text styles.
copyWith({TextStyle? displayLarge, TextStyle? displayMedium, TextStyle? displaySmall, TextStyle? headlineLarge, TextStyle? headlineMedium, TextStyle? headlineSmall, TextStyle? titleLarge, TextStyle? titleMedium, TextStyle? titleSmall, TextStyle? bodyLarge, TextStyle? bodyMedium, TextStyle? bodySmall, TextStyle? labelLarge, TextStyle? labelMedium, TextStyle? labelSmall, TextStyle? headline1, TextStyle? headline2, TextStyle? headline3, TextStyle? headline4, TextStyle? headline5, TextStyle? headline6, TextStyle? subtitle1, TextStyle? subtitle2, TextStyle? bodyText1, TextStyle? bodyText2, TextStyle? caption, TextStyle? button, TextStyle? overline}) → TextThemeCreates a copy of this text theme but with the given fields replaced with the new values.
라고 나와있다. 이를 코드와 같이 보면서 이해하면
- copyWith는 TextTheme의 Properties를 각각 바꿀 수 있는 것이고,
- apply는 한번에 모든 Properties의 속성을 바꿀 수 있는 것 같다.
'Dart > Flutter' 카테고리의 다른 글
[Flutter] SliverPersistentHeaderDelegate AutoCalculate Height (0) | 2023.06.14 |
---|---|
[Flutter][KakaoLogin] 플러터 카카오 로그인 구현 (1. 설정) (0) | 2023.04.23 |
[Flutter] Deep Link (0) | 2022.11.23 |
[Flutter] Widget에 Border 추가하기 (0) | 2022.11.17 |
[Flutter] StatefulWidget 알아보기 (0) | 2022.11.16 |
댓글