Skip to main content

Flutter common font file for my entire app

Problem: 

I want to create one class file that would be useful for text style for my entire app.How to achieve that?


Solution:

First you have to create a class file that will be as like below.

I had used the roboto font to my app.If you pass the color variable with data then it will show with that color.

Otherwise it will show default white color.

In largeBold i had used font to be roboto bold.

class AppFonts {
static TextStyle large({Color? color}) {
return TextStyle(
fontSize: Constants.largeFont,
fontFamily: 'Roboto',
color: color ?? Colors.white,
);
}
static TextStyle largeBold({Color? color}) {
return TextStyle(
fontSize: Constants.largeFont,
fontFamily: 'Roboto',
fontWeight: FontWeight.bold,
color: color ?? Colors.white,
);
}


}


Comments

Popular posts from this blog

Local variable for "serviceWorkerVersion" is deprecated in flutter

Problem:  Local variable for "serviceWorkerVersion" is deprecated. Use "{{flutter_service_worker_ version}}" template token instead. See  https://docs.flutter.dev/ platform-integration/web/ initialization  for more details. While try to run my flutter app in chrome it shows the above error. Solution: In script file it shows as like below < script > // The value below is injected by flutter build, do not touch. var serviceWorkerVersion = null ; </ script > Replace with below.It will works fine. < script > // The value below is injected by flutter build, do not touch. var serviceWorkerVersion = "{{flutter_service_worker_ version}}" ; </ script >