Secret To Custom Widget Themes

Fred Grott
5 min readApr 7, 2022

Okay, there is a trick to theme-ing your own created custom widgets. In Flutter slang, it’s one of the secret handshakes that shows that you are a skilled Flutter App developer and designer.

Let me show you the secret with a custom widget example.

Why Custom Widgets Cannot Have ThemeData Themes

Okay, so why do we need this? Well, with Dart extension methods, we can only add new fields to the new created instance of ThemeData via the Theme.of(context). Or, to put it another way, would be is that we cannot change the ThemeData constructor. So we need some way to theme our custom widgets.

That means if we create our custom widget to have the parameters we would set for in a theme; we can then move where our theme definition sits for that custom widget to the screen of the app.

Let me show you an implementation.

Screenshot And Video

First, the screenshot:

And the video:

--

--