ColorScheme constructor Null safety

const ColorScheme(
  1. {required Brightness brightness,
  2. required Color primary,
  3. required Color onPrimary,
  4. Color? primaryContainer,
  5. Color? onPrimaryContainer,
  6. required Color secondary,
  7. required Color onSecondary,
  8. Color? secondaryContainer,
  9. Color? onSecondaryContainer,
  10. Color? tertiary,
  11. Color? onTertiary,
  12. Color? tertiaryContainer,
  13. Color? onTertiaryContainer,
  14. required Color error,
  15. required Color onError,
  16. Color? errorContainer,
  17. Color? onErrorContainer,
  18. required Color background,
  19. required Color onBackground,
  20. required Color surface,
  21. required Color onSurface,
  22. Color? surfaceVariant,
  23. Color? onSurfaceVariant,
  24. Color? outline,
  25. Color? shadow,
  26. Color? inverseSurface,
  27. Color? onInverseSurface,
  28. Color? inversePrimary,
  29. Color? surfaceTint,
  30. @Deprecated('Use primary or primaryContainer instead. ' 'This feature was deprecated after v2.6.0-0.0.pre.') Color? primaryVariant,
  31. @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;