TechnoUrmish / Sizer

A flutter plugin for Easily make Flutter apps responsive. Automatically adapt UI to different screen sizes. Responsiveness made simple.
MIT License
240 stars 73 forks source link

Can't use the dp in a custom AppTheme #44

Open brandellcassio opened 2 years ago

brandellcassio commented 2 years ago

Hey guys!

So, I'm using a custom AppTheme, like this:

class AppThemes {
  static final TextTheme _lightTextTheme = TextTheme(
    headline2: TextStyle(
      fontFamily: 'Palanquin',
      fontSize: 26.sp,
      fontWeight: FontWeight.bold,
      color: Colors.neutralTxt,
    ),
   )
}

I did not put here the part of the code where I put the others styles. Also I set the MaterialApp like this:

  Sizer(builder: (context, orientation, deviceType) {
      return MaterialApp(
          theme: AppThemes.lightTheme
   )
}

My issue is: The .dp does not work when I use the text them in a widget.Like this:

Text(
              "Test"                
              style: Theme.of(context).textTheme.headline2,
              textAlign: TextAlign.left,
),

The other font styles (e.g. fontWeight, fontSize and color) works as expected. However, if I put the .dp directly in the widget style like this,

Text(
    "Test"                
     style: TextStyle(
         fontFamily: 'Palanquin',
          fontSize: 26.sp,
          fontWeight: FontWeight.bold,
          color: Colors.neutralTxt,
      ),
      textAlign: TextAlign.left,
),

it works as expected. Do you guys have any clue about what is happening? Thx!

fredgrott commented 2 years ago

From what I gather is Themes access is failing as when you use a Theme.of(context) ref it will create a new instance. So the work around is to manually apply the font size adjustment via copyWith() at the widget level rightinyour style Theme.of(context)_ ref.