harmonized method

ColorScheme harmonized()

Harmonizes semantic and custom ColorScheme colors with its primary color.

Harmonization makes adding and introducing new colors to your app more seamless by automatically shifting hue and chroma slightly so that a product's colors feel more cohesive with dynamic user colors.

Semantic colors (i.e. colors with meaning) include colors such as error. See https://m3.material.io/styles/color/the-color-system/custom-colors#harmonization for more information.

Subclasses of ColorScheme that add custom colors should re-implement harmonized. For example: import 'package:dynamic_color/dynamic_color.dart';

class CustomColorScheme extends ColorScheme { const CustomColorScheme(this.customYellow) : super(...);

final Color customYellow;

CustomColorScheme copyWith({ ... }) {}

CustomColorScheme harmonized() { return copyWith( customYellow: _harmonizeWithPrimary(customYellow), error: _harmonizeWithPrimary(error), onError: _harmonizeWithPrimary(onError), errorContainer: _harmonizeWithPrimary(errorContainer), onErrorContainer: _harmonizeWithPrimary(onErrorContainer), ); } }

Implementation

ColorScheme harmonized() {
  return copyWith(
    error: _harmonizeWithPrimary(error),
    onError: _harmonizeWithPrimary(onError),
    errorContainer: _harmonizeWithPrimary(errorContainer),
    onErrorContainer: _harmonizeWithPrimary(onErrorContainer),
  );
}