ColorData.of constructor

ColorData.of(
  1. bool dark, [
  2. ThemeData? theme
])

Implementation

factory ColorData.of(bool dark, [ThemeData? theme]) {
  theme ??= ThemeData();

  final base = ThemeColors.baseOf(dark, theme);

  final x = ColorTheme._i?._customs.entries.map((e) {
    if (e.value == null) return null;
    return MapEntry(e.key, e.value!.detect(dark));
  }).whereType<MapEntry<String, ThemeColors>>();

  Map<String, ThemeColors> colors =
      x == null || x.isEmpty ? {} : Map.fromEntries(x);

  final y = ColorTheme._i?._gradients.entries.map((e) {
    if (e.value == null) return null;
    return MapEntry(e.key, e.value!.detect(dark));
  }).whereType<MapEntry<String, ThemeGradients>>();

  Map<String, ThemeGradients> gradients =
      y == null || y.isEmpty ? {} : Map.fromEntries(y);

  return ColorData._(
    isDarkMode: dark,
    green: ColorTheme.greenOf(dark),
    grey: ColorTheme.greyOf(dark),
    blue: ColorTheme.blueOf(dark),
    red: ColorTheme.redOf(dark),
    orange: ColorTheme.orangeOf(dark),
    yellow: ColorTheme.yellowOf(dark),
    purple: ColorTheme.purpleOf(dark),
    pink: ColorTheme.pinkOf(dark),
    appbar: ThemeColors.of(_kAppbar, dark).defaults(
      primary: theme.appBarTheme.backgroundColor,
    ),
    base: base,
    background: ThemeColors.of(_kBackground, dark).defaults(
      primary: theme.scaffoldBackgroundColor,
    ),
    bottom: ThemeColors.of(_kBottom, dark).defaults(
      primary: theme.bottomAppBarTheme.color,
    ),
    card: ThemeColors.of(_kCard, dark).defaults(
      primary: theme.cardTheme.color ?? theme.cardColor,
    ),
    dialog: ThemeColors.of(_kDialog, dark).defaults(
      primary: theme.dialogTheme.backgroundColor,
    ),
    divider: ThemeColors.of(_kDivider, dark).defaults(
      primary: theme.dividerColor,
    ),
    highlight: ThemeColors.of(_kHighlight, dark).defaults(
      primary: theme.highlightColor,
    ),
    hint: ThemeColors.of(_kHint, dark).defaults(primary: theme.hintColor),
    hover: ThemeColors.of(_kHover, dark).defaults(primary: theme.hoverColor),
    icon: ThemeColors.of(_kIcon, dark).defaults(
      primary: theme.iconTheme.color,
    ),
    label: ThemeColors.of(_kLabel, dark),
    placeholder: ThemeColors.of(_kPlaceholder, dark),
    scaffold: ThemeColors.of(_kScaffold, dark).defaults(
      primary: theme.scaffoldBackgroundColor,
    ),
    shadow: ThemeColors.of(_kShadow, dark).defaults(
      primary: theme.shadowColor,
    ),
    surface: ThemeColors.of(_kSurface, dark).defaults(
      primary: theme.colorScheme.surface,
    ),
    splash: ThemeColors.of(_kSplash, dark).defaults(
      primary: theme.splashColor,
    ),
    text: ThemeColors.of(_kText, dark).defaults(
      primary: theme.textTheme.bodyMedium?.color,
      secondary: theme.textTheme.bodySmall?.color,
      tertiary: theme.textTheme.bodyLarge?.color,
    ),
    colors: colors,
    gradients: gradients,
  );
}