0

I'm trying to add clean architecture to my Flutter windows application and added some ThemeData to my project. I created a TextTheme and implemented all default sizes to it. Now I want to know if there is a clean way to always assign the default pixel ratio to my values and not every time I make a new implementation.

 static const TextTheme _textTheme = TextTheme(
    labelSmall: TextStyle(
      fontFamily: StringConst.POPPINS,
      fontSize: Sizes.TEXT_SIZE_8,
      color: AppColors.lightGrey,
      fontWeight: _semiBold,
      fontStyle: FontStyle.normal,
    ),
  );

This is an sample for an implementation where I use .copyWith to assign the default pixel ratio to my font size. The circumstances of my project forces me to assign it more or less at every type of size. What's the best way to NOT always need to copyWith but have the pixel ratio assigned?

final defaultPixelRatio = assignDefaultPixelRatio(context: context);
[...]
Text("something",
            style: Theme.of(context)
                .textTheme
                .labelSmall
                ?.copyWith(fontSize: Sizes.TEXT_SIZE_8 / defaultPixelRatio)),

To get the device pixel ratio I created the function:

double assignDefaultPixelRatio({
  required BuildContext context,
}) {
  return MediaQuery.of(context).devicePixelRatio;
}
Thoxh
  • 149
  • 9

0 Answers0