Flutter external text-style-sheet

160 Views Asked by At

I want to make a flutter app and in this app all the text styles should e similar. So, I want to have, like css, a stylesheet with e.g. 3 different textstyles and when I want to use one of that, I can call the methode like

Text(
'Text',
style: myTheme.styleType2,
),

Has anyone a good idea for this? Thanks a lot

1

There are 1 best solutions below

0
On

You can create a class for maintaining all of your TextStyles used in your project:

class TextStyles {
  static const headlineMedium = TextStyle(
    fontFamily: "Gilroy",
    color: ColorPalette.colorText,
    fontSize: 24,
    fontWeight: FontWeight.w600,
  );
  static const headlineRegular = TextStyle(
    fontFamily: "Gilroy",
    color: ColorPalette.colorText,
    fontSize: 24,
  );
  static const headlineSemi = TextStyle(
    fontFamily: "Gilroy",
    color: ColorPalette.colorText,
    fontSize: 16,
    fontWeight: FontWeight.w600,
  );
}

Now use these styles as a static data member

Text(
  "Hello World",
  style: TextStyles.headlineMedium,
)

For Exceptional Text, apply exceptional styles when copying the existing style, like:

Text(
  "Hello World",
  style: TextStyles.headlineMedium.copyWith(color: Colors.red),
)