ColorScheme.fromSeed constructor Null safety

  1. {required Color seedColor,
  2. Brightness brightness = Brightness.light,
  3. Color? primary,
  4. Color? onPrimary,
  5. Color? primaryContainer,
  6. Color? onPrimaryContainer,
  7. Color? secondary,
  8. Color? onSecondary,
  9. Color? secondaryContainer,
  10. Color? onSecondaryContainer,
  11. Color? tertiary,
  12. Color? onTertiary,
  13. Color? tertiaryContainer,
  14. Color? onTertiaryContainer,
  15. Color? error,
  16. Color? onError,
  17. Color? errorContainer,
  18. Color? onErrorContainer,
  19. Color? outline,
  20. Color? background,
  21. Color? onBackground,
  22. Color? surface,
  23. Color? onSurface,
  24. Color? surfaceVariant,
  25. Color? onSurfaceVariant,
  26. Color? inverseSurface,
  27. Color? onInverseSurface,
  28. Color? inversePrimary,
  29. Color? shadow,
  30. Color? surfaceTint}

Generate a ColorScheme derived from the given seedColor.

Using the seedColor as a starting point, a set of tonal palettes are constructed. These tonal palettes are based on the Material 3 Color system and provide all the needed colors for a ColorScheme. These colors are designed to work well together and meet contrast requirements for accessibility.

If any of the optional color parameters are non-null they will be used in place of the generated colors for that field in the resulting color scheme. This allows apps to override specific colors for their needs.

Given the nature of the algorithm, the seedColor may not wind up as one of the ColorScheme colors.

See also:


factory ColorScheme.fromSeed({
  required Color seedColor,
  Brightness brightness = Brightness.light,
  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? outline,
  Color? background,
  Color? onBackground,
  Color? surface,
  Color? onSurface,
  Color? surfaceVariant,
  Color? onSurfaceVariant,
  Color? inverseSurface,
  Color? onInverseSurface,
  Color? inversePrimary,
  Color? shadow,
  Color? surfaceTint,
}) {
  final Scheme scheme;
  switch (brightness) {
    case Brightness.light:
      scheme = Scheme.light(seedColor.value);
    case Brightness.dark:
      scheme = Scheme.dark(seedColor.value);
  return ColorScheme(
    primary: primary ?? Color(scheme.primary),
    onPrimary: onPrimary ?? Color(scheme.onPrimary),
    primaryContainer: primaryContainer ?? Color(scheme.primaryContainer),
    onPrimaryContainer: onPrimaryContainer ?? Color(scheme.onPrimaryContainer),
    secondary: secondary ?? Color(scheme.secondary),
    onSecondary: onSecondary ?? Color(scheme.onSecondary),
    secondaryContainer: secondaryContainer ?? Color(scheme.secondaryContainer),
    onSecondaryContainer: onSecondaryContainer ?? Color(scheme.onSecondaryContainer),
    tertiary: tertiary ?? Color(scheme.tertiary),
    onTertiary: onTertiary ?? Color(scheme.onTertiary),
    tertiaryContainer: tertiaryContainer ?? Color(scheme.tertiaryContainer),
    onTertiaryContainer: onTertiaryContainer ?? Color(scheme.onTertiaryContainer),
    error: error ?? Color(scheme.error),
    onError: onError ?? Color(scheme.onError),
    errorContainer: errorContainer ?? Color(scheme.errorContainer),
    onErrorContainer: onErrorContainer ?? Color(scheme.onErrorContainer),
    outline: outline ?? Color(scheme.outline),
    background: background ?? Color(scheme.background),
    onBackground: onBackground ?? Color(scheme.onBackground),
    surface: surface ?? Color(scheme.surface),
    onSurface: onSurface ?? Color(scheme.onSurface),
    surfaceVariant: surfaceVariant ?? Color(scheme.surfaceVariant),
    onSurfaceVariant: onSurfaceVariant ?? Color(scheme.onSurfaceVariant),
    inverseSurface: inverseSurface ?? Color(scheme.inverseSurface),
    onInverseSurface: onInverseSurface ?? Color(scheme.inverseOnSurface),
    inversePrimary: inversePrimary ?? Color(scheme.inversePrimary),
    shadow: shadow ?? Color(scheme.shadow),
    surfaceTint: surfaceTint ?? Color(scheme.primary),
    brightness: brightness,