2

I've seen some posts recommending to set fontSize or TextStyle for Text widget using Theme

// textStyle    
Theme.of(context).textTheme.bodySmall 

OR

// fontSize
Theme.of(context).textTheme.bodySmall.fontSize 

What benefit will I get by setting these parameters using Theme.of(context) at runtime, when I can simply declare font sizes as constants?

ASAD HAMEED
  • 2,296
  • 1
  • 20
  • 36

1 Answers1

0

You can either define app-wide themes or use Theme widgets that represent the colors and font styles for a particular part of the application. App-wide themes are Theme widgets created at the root of an app by the MaterialApp.

After defining a Theme, use it within your widgets. Flutter’s Material widgets also use your Theme to set the background colors and font styles for AppBars, Buttons, Checkboxes, and more.

You can ref this below link: https://docs.flutter.dev/cookbook/design/themes

Robert S
  • 626
  • 6
  • 13