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

Using 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.

It would be nice if it was possible to also provide these as static extensions on ThemeData, in away that would enable a syntax like this:

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

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

on

Static Methods

dark({FlexSchemeColor? colors, FlexScheme? scheme, ColorScheme? colorScheme, int usedColors = 6, FlexSurfaceMode? surfaceMode, int blendLevel = 0, FlexAppBarStyle? appBarStyle, double? appBarOpacity, bool transparentStatusBar = true, double? appBarElevation, double? bottomAppBarElevation, FlexTabBarStyle? tabBarStyle, Color? primary, Color? primaryContainer, Color? secondary, Color? secondaryContainer, Color? tertiary, Color? tertiaryContainer, Color? error, Color? surface, Color? background, Color? scaffoldBackground, Color? dialogBackground, Color? appBarBackground, Color? onPrimary, Color? onPrimaryContainer, Color? onSecondary, Color? onSecondaryContainer, Color? onTertiary, Color? onTertiaryContainer, Color? onSurface, Color? onBackground, Color? onError, Color? surfaceTint, bool darkIsTrueBlack = false, bool swapColors = false, bool tooltipsMatchBackground = false, FlexSubThemesData? subThemesData, FlexKeyColors? keyColors, bool useMaterial3ErrorColors = false, FlexTones? tones, VisualDensity? visualDensity, TextTheme? textTheme, TextTheme? primaryTextTheme, String? fontFamily, List<String>? fontFamilyFallback, String? package, MaterialTapTargetSize? materialTapTargetSize, PageTransitionsTheme? pageTransitionsTheme, InteractiveInkFeatureFactory? splashFactory, TargetPlatform? platform, Typography? typography, bool applyElevationOverlayColor = true, bool useMaterial3 = false, bool swapLegacyOnMaterial3 = false, Iterable<ThemeExtension>? extensions}) ThemeData
Returns a ThemeData object defined by factory FlexColorScheme.dark and its FlexColorScheme.toTheme method.
light({FlexSchemeColor? colors, FlexScheme? scheme, ColorScheme? colorScheme, int usedColors = 6, FlexSurfaceMode? surfaceMode, int blendLevel = 0, FlexAppBarStyle? appBarStyle, double? appBarOpacity, bool transparentStatusBar = true, double? appBarElevation, double? bottomAppBarElevation, FlexTabBarStyle? tabBarStyle, Color? primary, Color? primaryContainer, Color? secondary, Color? secondaryContainer, Color? tertiary, Color? tertiaryContainer, Color? error, Color? surface, Color? background, Color? scaffoldBackground, Color? dialogBackground, Color? appBarBackground, Color? onPrimary, Color? onPrimaryContainer, Color? onSecondary, Color? onSecondaryContainer, Color? onTertiary, Color? onTertiaryContainer, Color? onSurface, Color? onBackground, Color? onError, Color? surfaceTint, bool lightIsWhite = false, bool swapColors = false, bool tooltipsMatchBackground = false, FlexSubThemesData? subThemesData, FlexKeyColors? keyColors, bool useMaterial3ErrorColors = false, FlexTones? tones, VisualDensity? visualDensity, TextTheme? textTheme, TextTheme? primaryTextTheme, String? fontFamily, List<String>? fontFamilyFallback, String? package, MaterialTapTargetSize? materialTapTargetSize, PageTransitionsTheme? pageTransitionsTheme, InteractiveInkFeatureFactory? splashFactory, TargetPlatform? platform, Typography? typography, bool applyElevationOverlayColor = true, bool useMaterial3 = false, bool swapLegacyOnMaterial3 = false, Iterable<ThemeExtension>? extensions}) ThemeData
Returns a ThemeData object defined by factory FlexColorScheme.light and its FlexColorScheme.toTheme method.