Customizing UI with Themes in Flutter
Customizing the UI with themes in Flutter allows you to define consistent styles (like colors, fonts, shapes, etc.) across your app. This helps maintain a uniform look and feel and makes it easier to make global changes to your app’s appearance.
Here’s a quick breakdown of how to use themes in Flutter:
๐ 1. Using ThemeData
for Light & Dark Themes
-
theme
: The light theme. -
darkTheme
: The dark theme. -
themeMode
: Defines which theme to use (light/dark/system).
๐จ 2. Customizing Colors, Typography, Buttons, etc.
You can customize:
-
appBarTheme
-
inputDecorationTheme
(forTextField
) -
cardTheme
-
iconTheme
-
and many more...
๐ 3. Using Theme.of(context)
To access theme values in widgets:
๐งฉ 4. Custom Themes with Extensions
If you need to define your own custom theme values:
Use it like:
Then retrieve with:
⚡ Bonus Tips
-
Use
ThemeMode.system
to respect the user's OS theme preference. -
For animations or transitions between themes, use
AnimatedTheme
. -
You can hot-reload theme changes for faster dev feedback.
Comments
Post a Comment