본문 바로가기

flutter

TextStyle 정의하기

TextStyle 재활용 할 수 있게 정의하기

class CustomTextStyle extends TextStyle {
  const CustomTextStyle({
    required String fontFamily,
    required Color color,
    required double fontSize,
    required FontWeight fontWeight,
    int? height,
    Paint? foreground,
  }) : super(
          fontFamily: fontFamily,
          color: color,
          fontSize: fontSize,
          fontWeight: fontWeight,
          height: height == null ? null : height / fontSize,
          leadingDistribution: TextLeadingDistribution.even,
          foreground: foreground,
        );
}

피그마에서 font관련 정보를 받아올 때 그대로 입력하기 위해 height를 계산

TextStyle 내의 height 속성은 글꼴 크기의 배수이다. 텍스트의 높이는 fontSize * height 이다.

 

https://api.flutter.dev/flutter/painting/TextStyle-class.html

 

TextStyle class - painting library - Dart API

An immutable style describing how to format and paint text. Bold Here, a single line of text in a Text widget is given a specific style override. The style is mixed with the ambient DefaultTextStyle by the Text widget. assignment const Text( 'No, we need b

api.flutter.dev

 

 

leadingDistribution

폰트 정의 (색상, 사이즈, 높이 등)

class Spoqa {
  static const spoqa = "Spoqa";

  static const black_s10_w500_h14 = CustomTextStyle(fontFamily: spoqa, color: ColorPalette.black, fontSize: 10, fontWeight: FontWeight.w500, height: 14);
  static const black_s20_w700_h28 = CustomTextStyle(fontFamily: spoqa, color: ColorPalette.black, fontSize: 20, fontWeight: FontWeight.w700, height: 28);
}

 

'flutter' 카테고리의 다른 글

BoxConstraints forces an infinite width  (0) 2022.05.26
IntrinsicWidth, UnconstrainedBox  (0) 2022.05.23
flutter + firebase 연동하기  (0) 2022.05.13
flutter CustomPaint  (0) 2022.05.12
flutter listview (flutter codlabs)  (0) 2022.05.10