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, FlexFixedColorStyle? fixedColorStyle, FlexAppBarStyle? appBarStyle, double? appBarOpacity, bool transparentStatusBar = true, double? appBarElevation, double? bottomAppBarElevation, FlexTabBarStyle? tabBarStyle, Color? primary, Color? primaryLightRef, Color? onPrimary, Color? primaryContainer, Color? onPrimaryContainer, Color? secondary, Color? secondaryLightRef, Color? onSecondary, Color? secondaryContainer, Color? onSecondaryContainer, Color? tertiary, Color? tertiaryLightRef, Color? onTertiary, Color? tertiaryContainer, Color? onTertiaryContainer, Color? error, Color? onError, Color? errorContainer, Color? onErrorContainer, Color? surface, Color? onSurface, Color? scaffoldBackground, Color? dialogBackground, Color? appBarBackground, Color? surfaceTint, bool darkIsTrueBlack = false, bool swapColors = false, bool tooltipsMatchBackground = false, FlexSubThemesData? subThemesData, FlexKeyColors? keyColors, bool useMaterial3ErrorColors = false, FlexTones? tones, FlexSchemeVariant? variant, 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, NoDefaultCupertinoThemeData? cupertinoOverrideTheme, bool useMaterial3 = true, bool swapLegacyOnMaterial3 = false, Iterable<ThemeExtension> ? extensions, Color? background, Color? onBackground}) → 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, FlexFixedColorStyle? fixedColorStyle, FlexAppBarStyle? appBarStyle, double? appBarOpacity, bool transparentStatusBar = true, double? appBarElevation, double? bottomAppBarElevation, FlexTabBarStyle? tabBarStyle, Color? primary, Color? onPrimary, Color? primaryContainer, Color? onPrimaryContainer, Color? secondary, Color? onSecondary, Color? secondaryContainer, Color? onSecondaryContainer, Color? tertiary, Color? onTertiary, Color? tertiaryContainer, Color? onTertiaryContainer, Color? error, Color? onError, Color? errorContainer, Color? onErrorContainer, Color? surface, Color? onSurface, Color? scaffoldBackground, Color? dialogBackground, Color? appBarBackground, Color? surfaceTint, bool lightIsWhite = false, bool swapColors = false, bool tooltipsMatchBackground = false, FlexSubThemesData? subThemesData, FlexKeyColors? keyColors, bool useMaterial3ErrorColors = false, FlexTones? tones, FlexSchemeVariant? variant, 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, NoDefaultCupertinoThemeData? cupertinoOverrideTheme, bool useMaterial3 = true, bool swapLegacyOnMaterial3 = false, Iterable<ThemeExtension> ? extensions, Color? background, Color? onBackground}) → ThemeData - Returns a ThemeData object defined by factory FlexColorScheme.light and its FlexColorScheme.toTheme method.