We can use the theme to set colors and properties to our app and widgets that way we don't have to specify colors for every widget manually and if we do, we should refer the color back to our theme object. doing this makes life easier and if we do want to change the colors we could do so by just changing the theme color as opposed to going to every widget and changing the colors there.
we specify theme in the material app such as below:
PrimarySwatch is the primary shades of color used in widgets, meaning flutter will adjust many shades of colors used in different widgets using this color.
primary color and accent color are self-explanatory since they are responsible for the primary colors and secondary colors used in different widgets.
to access the theme colors in your widget you can use the following syntax:
Theme.of(context). -- this will enables you to choose any of the theme-defined colors or properties.
Adding custom fonts:
to add custom fonts you need to place your .ttf file which are font files in your flutter directory and let flutter know where this direcotry is via pubspec.yaml
usually, it's placed in an assets folder inside a font's directory. you can then give your fonts names via the "family" parameter and use that name in your apps
use the fonts in your theme:
and use the theme setting in your widgets, this way the styles are managed globally.
My text widget with a smaller text
My Text widget with the main title