ColorScheme constructor Null safety
- {required Brightness brightness,
- required Color primary,
- required Color onPrimary,
- Color? primaryContainer,
- Color? onPrimaryContainer,
- required Color secondary,
- required Color onSecondary,
- Color? secondaryContainer,
- Color? onSecondaryContainer,
- Color? tertiary,
- Color? onTertiary,
- Color? tertiaryContainer,
- Color? onTertiaryContainer,
- required Color error,
- required Color onError,
- Color? errorContainer,
- Color? onErrorContainer,
- required Color background,
- required Color onBackground,
- required Color surface,
- required Color onSurface,
- Color? surfaceVariant,
- Color? onSurfaceVariant,
- Color? outline,
- Color? shadow,
- Color? inverseSurface,
- Color? onInverseSurface,
- Color? inversePrimary,
- Color? surfaceTint,
- @Deprecated('Use primary or primaryContainer instead. ' 'This feature was deprecated after v2.6.0-0.0.pre.') Color? primaryVariant,
- @Deprecated('Use secondary or secondaryContainer instead. ' 'This feature was deprecated after v2.6.0-0.0.pre.') Color? secondaryVariant}
Create a ColorScheme instance from the given colors.
ColorScheme.fromSeed can be used as a simpler way to create a full color scheme derived from a single seed color.
For the color parameters that are nullable, it is still recommended that applications provide values for them. They are only nullable due to backwards compatibility concerns.
If a color is not provided, the closest fallback color from the given
colors will be used for it (e.g. primaryContainer
will default
to primary). Material Design 3 makes use of these colors for many
component defaults, so for the best results the application should
supply colors for all the parameters. An easy way to ensure this is to
use ColorScheme.fromSeed to generate a full set of colors.
During the migration to Material Design 3, if an app's ThemeData.useMaterial3 is false, then components will only use the following colors for defaults:
Implementation
const ColorScheme({
required this.brightness,
required this.primary,
required this.onPrimary,
Color? primaryContainer,
Color? onPrimaryContainer,
required this.secondary,
required this.onSecondary,
Color? secondaryContainer,
Color? onSecondaryContainer,
Color? tertiary,
Color? onTertiary,
Color? tertiaryContainer,
Color? onTertiaryContainer,
required this.error,
required this.onError,
Color? errorContainer,
Color? onErrorContainer,
required this.background,
required this.onBackground,
required this.surface,
required this.onSurface,
Color? surfaceVariant,
Color? onSurfaceVariant,
Color? outline,
Color? shadow,
Color? inverseSurface,
Color? onInverseSurface,
Color? inversePrimary,
Color? surfaceTint,
@Deprecated(
'Use primary or primaryContainer instead. '
'This feature was deprecated after v2.6.0-0.0.pre.'
)
Color? primaryVariant,
@Deprecated(
'Use secondary or secondaryContainer instead. '
'This feature was deprecated after v2.6.0-0.0.pre.'
)
Color? secondaryVariant,
}) : assert(brightness != null),
assert(primary != null),
assert(onPrimary != null),
assert(secondary != null),
assert(onSecondary != null),
assert(error != null),
assert(onError != null),
assert(background != null),
assert(onBackground != null),
assert(surface != null),
assert(onSurface != null),
_primaryContainer = primaryContainer,
_onPrimaryContainer = onPrimaryContainer,
_secondaryContainer = secondaryContainer,
_onSecondaryContainer = onSecondaryContainer,
_tertiary = tertiary,
_onTertiary = onTertiary,
_tertiaryContainer = tertiaryContainer,
_onTertiaryContainer = onTertiaryContainer,
_errorContainer = errorContainer,
_onErrorContainer = onErrorContainer,
_surfaceVariant = surfaceVariant,
_onSurfaceVariant = onSurfaceVariant,
_outline = outline,
_shadow = shadow,
_inverseSurface = inverseSurface,
_onInverseSurface = onInverseSurface,
_inversePrimary = inversePrimary,
_primaryVariant = primaryVariant,
_secondaryVariant = secondaryVariant,
_surfaceTint = surfaceTint;