convert function

FluentColors convert(
  1. MaterialColor materialColor, [
  2. Brightness brightness = Brightness.light
])

Implementation

FluentColors convert(MaterialColor materialColor,
    [Brightness brightness = Brightness.light]) {
  final fluentColor = <int, Color>{};
  for (var i = 0; i <= 15; i++) {
    const materialStep = 900 / 16;
    final materialLevel = 900 - i * materialStep;
    final rest = (materialLevel % 100).toInt();
    final percentage = rest / 100;
    final lower = materialLevel ~/ 100 * 100;
    final higher = rest == 0 ? lower : lower + 100;
    final lowerColor = materialColor[lower] ?? Colors.white;
    final higherColor = materialColor[higher] ?? Colors.black;
    fluentColor[(i + 1) * 10] = ColorTween(
      begin: lowerColor,
      end: higherColor,
    ).lerp(percentage)!;
  }

  return switch (brightness) {
    Brightness.light => FluentColors(
        brandBackground1Rest: fluentColor[80]!,
        brandBackground1Pressed: fluentColor[50]!,
        brandBackground1Selected: fluentColor[60]!,
        brandBackground2Rest: fluentColor[70]!,
        brandBackground2Pressed: fluentColor[40]!,
        brandBackground2Selected: fluentColor[50]!,
        brandBackground3Rest: fluentColor[60]!,
        brandBackgroundTintRest: fluentColor[150]!,
        brandBackgroundDisabledRest: fluentColor[140]!,
        brandForeground1Rest: fluentColor[80]!,
        brandForeground1Pressed: fluentColor[50]!,
        brandForeground1Selected: fluentColor[60]!,
        brandForegroundTintRest: fluentColor[60]!,
        brandForegroundDisabled1Rest: fluentColor[90]!,
        brandForegroundDisabled2Rest: fluentColor[140]!,
        brandStroke1Rest: fluentColor[80]!,
        brandStroke1Pressed: fluentColor[50]!,
        brandStroke1Selected: fluentColor[60]!,
      ),
    Brightness.dark => FluentColors(
        brandBackground1Rest: fluentColor[100]!,
        brandBackground1Pressed: fluentColor[130]!,
        brandBackground1Selected: fluentColor[120]!,
        brandBackground2Rest: Colors.transparent,
        brandBackground2Pressed: Colors.transparent,
        brandBackground2Selected: Colors.transparent,
        brandBackground3Rest: Colors.transparent,
        brandBackgroundTintRest: fluentColor[40]!,
        brandBackgroundDisabledRest: fluentColor[40]!,
        brandForeground1Rest: fluentColor[100]!,
        brandForeground1Pressed: fluentColor[130]!,
        brandForeground1Selected: fluentColor[120]!,
        brandForegroundTintRest: fluentColor[130]!,
        brandForegroundDisabled1Rest: fluentColor[90]!,
        brandForegroundDisabled2Rest: fluentColor[40]!,
        brandStroke1Rest: fluentColor[100]!,
        brandStroke1Pressed: fluentColor[130]!,
        brandStroke1Selected: fluentColor[120]!,
      ),
  };
}