Configure the Material 3 Theme for the Flutter project

Tram Ho

Hi guys, in a Mobile app or Web project, configuring the theme for the project is one of the first steps when building an initial project. Today, I will learn together how to configure the Theme according to the Material 3 standard.

Basic understanding of Theme

Themes are the colors of the components, brightness, contrast, shadow, density, .. of an application or website.

Theme helps you consistent design of an application, website. It allows you to customize all design aspects of your project to meet the specific needs of your business or brand.

There are many design systems that support the definition of a Theme for an application, the most popular of which are:

To talk about Theme or Design Systems is a whole field in design. However, within the scope of the article, today I only learn the basics and how to configure the Theme for Flutter project using Material UI 3. Let’s go!!!!

First steps.

The main components include: Color, Elevation, Icons, Motion, Shape, Typography. Within the scope of this article, I will focus on Color and Typography.

Key Colors

Key colors is a collection of 5 main colors with 13 different tones

Accent colors:

  • Primary key color: primary color used in app highlights like FAB, CTA buttons, key app components.
  • Secondary key color: used in less prominent components like Filter Chip.
  • Tertiary key color (3rd color): used to balance 2 primary colors or bring attention to a detail in a component.

Neutral colors

  • Neutral key color: often used to define a color for a background, text or icon that needs high emphasis.
  • Neutral variant key color: text, medium press icon, outline button,..

For additional components, you can refer to this docs: https://m3.material.io/styles/color/the-color-system/key-colors-tones

Material Theme Builder

I can use Google’s Material Theme Builder support tool to create a theme according to the basic Material standard by choosing the main color, the tool will automatically create a Color Palette.

In addition, you can refer to the Material 3 UI Kit to shape the components used.

Configure themes for Flutter

Here, I use GetX to support theme creation as well as state management (in addition, you can use block, Provider … depending on your preferences).

Color Theme

I can use this basic, then I can create a standard Material3 theme for the application.

However, if you have more customization, there are also the following configs according to the desired function:

Or you can create a color scheme file (this code I refer to a certain blog but forgot the name 🥲).

Text theme

You can also configure properties for Text in this way.

Remember to Import into DAppTheme to use it

Using

Can be simply used as follows:

Dark Mode and Light Mode.

To switch between dark mode and light mode, we create a switch button. To save the theme value when restarting the application, you can use shared_preferences to save the variable in local storage.

Epilogue

Through the last article, we have configured the Material Theme for the Flutter project. See you in the next article. Happy New Year 2023, wish everyone a happy, more and more successful in work and life. Happy New Year

Source code

https://github.com/AnhQuangCee/demo_theme

References

Material Design

Use themes to share colors and font styles

Share the news now

Source : Viblo