Better approach to set font size in flutter - flutter

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?

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

Related

How do I know which color is applied to which component in ColorScheme flutter?

The description says like below and its not ENOUGH!!!! and I am tired!!
ColorScheme is a set of 25 colors based on the Material spec that can be used to configure the color properties of most components.
The main accent color groups in the scheme are primary, secondary, and tertiary.
I'd like to know which color applied to which component in flutter
For example,
The primary color is applied to FloatingActionButton like that!
Well, as it says, Flutter follows the Material design system and color scheme, so you can know what widgets and elements those colors are used from the official Material design website, check it:
https://m2.material.io/design/color/the-color-system.html

Flutter CupertinoTheme is too limiting. How would I go about adding more Theme parmaters?

Basically CupertinoThemeData has only 4 Colors that can be set. There is no parameter for let's say tiles. Should I just define some colors globally that I change inside the same function that switches theme? Or should I wrap my CupertinoThemeData inside a normal ThemeData (which has way more parameters)?
I am new to theming and was wondering what the best practices are.

Flutter List Tile inherits theme from themedata?

Does ListTile widgets automatically inherit the listTile theme data declared in the app's theme in flutter?
I gave a shape in the themedata, but it is not reflecting in the ui

Flutter: Specify textstyle of Button in Theme

is it possible to influence the textStyle of a Button through the theme? In this particular case, I want every button label to have a specific fontWeight.
The ButtonTextTheme is only responsible for colors.
I know I can style the child of the button itself but I wanted to have the styling on theme level.
Now I'd need to create a custom Button Widget that does that for me

What is the difference between Material and MaterialApp in Flutter?

I am developing an app using Flutter. If I choose MaterialApp as the parent widget of my app, all Text widgets in my app are underlined yellow. On the other hand, if I just use Material as the parent widget, no yellow lines are shown under the Text widgets.
What is the difference between Material and MaterialApp?
MaterialApp is a widget that introduces many interesting tools such as Navigator or Theme to help you develop your app.
Material is, on the other hand, a widget used to define a UI element respecting Material rules. It defines what elevation is, shape, and stuff. Then reused by many material widgets such as Appbar or Card or FloatingButton.
The yellow underlines you can find in Text is introduced by MaterialApp as a fallback Theme. It is here for debug purpose, to warn you that you need to use Material somewhere above your Text.
In short, use both. You should have a MaterialApp near the root of your app. And then use widgets that introduce a Material instance (Such a Scaffold, Appbar, Dialog, ...) when you want to use Text or InkWell.
MaterialApp : The MaterialApp configures the top-level Navigator to search for routes or to define Home.
Material : For child UI widgets rendering & effects.