Custom ThemeData Flutter - Extension

In Flutter it is possible to adapt the colors of the app to the current theme of the app - light or dark theme. However, the ThemeData object only has a set of predefined colors which can be changed e.g. scaffoldBackgroundColor, color of the AppBarTheme etc. If you wanted a specific color for a icon in your app which changes also according to the theme, it is not possible to specify on the ThemeData.

With this code it is possible to do just that with a CustomThemeData:

I need a custom Color which changes, when the AppTheme changes.
— Problem InShort

The CustomAppTheme is an InheritedWidget and therefore the CustomAppThemeData can be retrieved the same way ThemeData is.

CustomAppThemeData can be appended with your custom colors.

It is important to note that the CustomAppThemeData is only available in child widgets of the CustomAppTheme widget, so it is desired to have the CustomAppTheme as high up in the widget tree as possible.

The implemenation is very similar to the internal implementation of the ThemeData usage, it is very fast.