'Dynamic theme properties in Flutter which can be set in runtime

I would like to create my own theme properties which can be set in runtime dynamically. I tried to create an extension for the TextTheme which looks like that:


extension CustomTextTheme on TextTheme {
  TextStyle get heading => themeMode == ThemeMode.light
      ? TextStyle(
          color: GlobalTheme.defaultLightTheme.textTheme.headline.color,
          fontSize: GlobalTheme.defaultLightTheme.textTheme.headline.fontSize,
        )
      : TextStyle(
          color: GlobalTheme.defaultDarkTheme.textTheme.headline.color,
          fontSize: GlobalTheme.defaultLightTheme.textTheme.headline.fontSize,
        );
}

The question is how I can change the extension properties on runtime dynamically. What I want to archive with this is, that I can load a "theme config" from the server and set that theme on each device dynamically.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source