Search code examples
fluttertextstyle

Flutter TextStyle / fontSize


I would like the TextStyle / fontSize to simplify my app.

for this it would be necessary to make the line "

fontSize: Get.width * .030,

" of the attached code available, similar to the color "

{Color color = Colors.white}

This is the code I want to customize ...

TextStyle _textStyle({Color color = Colors.white}) {
  return GoogleFonts.getFont(
    'Unica One',
    fontSize: Get.width * .030,
    color: color,
    letterSpacing: 0.5,
  );
}

And it should look something like that, but unfortunately I don't know exactly how to put it together correctly

TextStyle _textStyle({Color color = Colors.white}{FontSize fontSize = Get.width * .030}) {
  return GoogleFonts.getFont(
    'Unica One',
    fontSize: fontSize,
    color: color,
    letterSpacing: 0.5,
  );
}

Solution

  • Text class with style,

    class StoryText extends Text {
      StoryText(String title, {Color mColor, double mFontSize})
          : super(title,
                style: GoogleFonts.getFont(
                  'Unica One',
                  fontSize: mFontSize,
                  color: mColor,
                  letterSpacing: 0.5,
                ));
    }
    
    // Use of above class
    StoryText('title', mColor: Colors.red, mFontSize: Get.width * .030,),