Flutter 2: How to extend ThemeData
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:
With dart 2.7, this is finally possible by using Extension methods.
Note
- It’s possible to extend
ThemeData
object, but most of us only need a custom color palette. For simplicity, I would instead extend theColorScheme
object in the following example. - Flutter team is moving the color dependencies of Material components from
ThemeData
toColorScheme
, let’s work with this future-proof solution.
Solution
Let’s make a bootstrap flavored color scheme: