개발/Flutter

[Flutter] GoogleFonts 사용하기 (폰트 변경 하기)

라보떼 2023. 1. 12. 15:09

 

 

GoogleFonts

기본 시스템 글꼴 외 다양한 폰트를 간편히 사용하고 싶을때 사용해보면 좋을듯합니다.
모든 글꼴을 저장할 필요 없이 1,400개 이상의 글꼴을 사용할 수 있습니다.

 

 

우선 pubspec.yaml 에 의존성을 추가 합니다.

google_fonts: ^3.0.1

 

 

 

사용법은 간단합니다.

 

Text(
  'This is Google Fonts',
  style: GoogleFonts.amiko(),
)

기존 Text widget의 style 에 추가 합니다.

 

 

Text(
  'This is Google Fonts',
  style: GoogleFonts.amiko(fontSize: 20, color: Colors.black),
),

TextStyle 은 GoogleFonts 내부로 추가 합니다.

fonts

 

 

그리고,  Theme에 추가해 모든 Text에 적용하는 방법이 있습니다.

 

final appTheme = ThemeData(
    primarySwatch: Colors.grey,
    canvasColor: Colors.white,
    textTheme: GoogleFonts.aladinTextTheme()
    )

해당 Theme를 App Theme에 추가하면 모든 Text에 적용하여 사용 가능합니다

 

 

 

 

 

[pub.dev] https://pub.dev/packages/google_fonts

 

google_fonts | Flutter Package

A Flutter package to use fonts from fonts.google.com.

pub.dev