아래 코드 느낌으로 theme 정의해서 사용 가능하다. google_fonts 패키지 사용하면 폰트 적용도 쉽게 해 볼 수 있다.
import'package:flutter/material.dart';import'package:google_fonts/google_fonts.dart';classEllasNotesThemeData{staticThemeDatalightThemeData=themeData();// 실제 쓸 때는 요걸로 쓸 거임
staticThemeDatathemeData(){// 실제 ThemeData 만듬
finalbase=ThemeData.light();returnbase.copyWith(textTheme:_buildEllasNotesTextTheme(base.textTheme),// ...
// textTheme 외에도 appBarTheme, primaryTheme, colorScheme 등 override 할 수 있는 항목 매우 많음
);}staticTextTheme_buildEllasNotesTextTheme(TextThemebase){// TextTheme 생성
returnbase.copyWith(titleLarge:GoogleFonts.robotoSlab(textStyle:base.titleLarge),// main text
bodyMedium:GoogleFonts.nanumGothic(textStyle:base.bodyMedium),// note
// ...
);}}
앱 진입 부분에서 theme 지정
classMyAppextendsStatelessWidget{constMyApp({super.key});@overrideWidgetbuild(BuildContextcontext){returnMaterialApp(title:"Ella's Notes",theme:EllasNotesThemeData.lightThemeData,// 위에서 정의한 theme 적용!!
initialRoute:'home',routes:{"home":(context)=>constHomePage(),"game":(context)=>constGamePage(),},builder:EasyLoading.init(),);}}