FlexThemeData extension

A convenience extension on ThemeData to define a FlexColorScheme object and return the ThemeData object defined by its instance, using its FlexColorScheme.toTheme method in one go.

Provided convenience extensions are:

  • FlexThemeData.light(), based on FlexColorScheme.light().toTheme
  • FlexThemeData.dark(), based on FlexColorScheme.dark().toTheme

The goal is to be able to provide these as static extensions on ThemeData, so it would be possible to say:

  • ThemeData.flexLight(), based on FlexColorScheme.light().toTheme
  • ThemeData.flexDark(), based on FlexColorScheme.dark().toTheme

Dart does not yet support such extensions, see: https://github.com/dart-lang/language/issues/723

Using e.g. FlexThemeData.light is a bit shorter than FlexColorScheme.light.toTheme, and it may feel more familiar since you get a ThemeData object directly that you can use just like any other ThemeData object produced by Flutter SDK built in ThemeData factory constructors.

For advanced theming, when constructing elaborate themes where sub themes need access to the ColorScheme as defined by your FlexColorScheme. Consider using FlexColorScheme, then get the ColorScheme it defines with FlexColorScheme.toScheme and use colors from this scheme or the entire ColorScheme in you sub-themes, that you then apply with ThemeData.copyWith to the ThemeData given by FlexColorScheme.toTheme. You can of course do this with these extensions too, but in that case you will need to store the theme in an intermediate ThemeData object.

on

Static Methods

dark({FlexSchemeColor? colors, FlexScheme? scheme, ColorScheme? colorScheme, int usedColors = 4, FlexSurface surfaceStyle = FlexSurface.material, FlexSurfaceMode? surfaceMode, int blendLevel = 0, FlexAppBarStyle appBarStyle = FlexAppBarStyle.material, double appBarOpacity = 1, double appBarElevation = 0, double? bottomAppBarElevation, FlexTabBarStyle tabBarStyle = FlexTabBarStyle.forAppBar, Color? primary, Color? primaryVariant, Color? secondary, Color? secondaryVariant, Color? error, Color? surface, Color? background, Color? scaffoldBackground, Color? dialogBackground, Color? appBarBackground, Color? onPrimary, Color? onSecondary, Color? onSurface, Color? onBackground, Color? onError, bool darkIsTrueBlack = false, bool swapColors = false, bool tooltipsMatchBackground = false, bool transparentStatusBar = true, VisualDensity? visualDensity, TextTheme? textTheme, TextTheme? primaryTextTheme, String? fontFamily, TargetPlatform? platform, Typography? typography, bool applyElevationOverlayColor = true, bool useSubThemes = false, FlexSubThemesData? subThemesData}) ThemeData
Returns a ThemeData object defined by factory FlexColorScheme.dark and its FlexColorScheme.toTheme method.
light({FlexSchemeColor? colors, FlexScheme? scheme, ColorScheme? colorScheme, int usedColors = 4, FlexSurface surfaceStyle = FlexSurface.material, FlexSurfaceMode? surfaceMode, int blendLevel = 0, FlexAppBarStyle appBarStyle = FlexAppBarStyle.primary, double appBarOpacity = 1, double appBarElevation = 0, double? bottomAppBarElevation, FlexTabBarStyle tabBarStyle = FlexTabBarStyle.forAppBar, Color? primary, Color? primaryVariant, Color? secondary, Color? secondaryVariant, Color? error, Color? surface, Color? background, Color? scaffoldBackground, Color? dialogBackground, Color? appBarBackground, Color? onPrimary, Color? onSecondary, Color? onSurface, Color? onBackground, Color? onError, bool lightIsWhite = false, bool swapColors = false, bool tooltipsMatchBackground = false, bool transparentStatusBar = true, VisualDensity? visualDensity, TextTheme? textTheme, TextTheme? primaryTextTheme, String? fontFamily, TargetPlatform? platform, Typography? typography, bool applyElevationOverlayColor = true, bool useSubThemes = false, FlexSubThemesData? subThemesData}) ThemeData
Returns a ThemeData object defined by factory FlexColorScheme.light and its FlexColorScheme.toTheme method.