Flutter 2: How to extend ThemeData

Crizant Lai
2 min readDec 14, 2019

Update in 2022: With the release of Flutter 3.0, we have a better solution:

Problem

The way to extend ThemeData in Flutter has been a frequently asked question on StackOverflow: Is it possible “extend” ThemeData in Flutter.

There are even issues created in the Flutter official repository:

  1. Add custom properties to ThemeData
  2. Feature request: Extend ThemeData with app-specific palettes

With dart 2.7, this is finally possible by using Extension methods.

Note

  1. It’s possible to extend ThemeData object, but most of us only need a custom color palette. For simplicity, I would instead extend the ColorScheme object in the following example.
  2. Flutter team is moving the color dependencies of Material components from ThemeData to ColorScheme, let’s work with this future-proof solution.

Solution

Let’s make a bootstrap flavored color scheme:

--

--

Crizant Lai

A TypeScript/Flutter developer who love technical stuffs.