operator | method Null safety

Color operator |(
  1. dynamic others
)

Color Or Operator

Random Color access.

If others is Color, the return value is this or others.

If others is List<Color>, the return value is this or one of the entries from others.

Implementation

Color operator |(dynamic others) => (others is Color)
    // Expanding first enables the mingling of Color-subtype objects,
    // like MaterialColors and MaterialAccentColors.
    ? (List.from([
        [others] + [this]
      ].expand((list) => list).toList())
          ..shuffle())
        .first
    : (others is List<Color>)
        ? (List.from([
            others,
            [this]
          ].expand((list) => list).toList())
              ..shuffle())
            .first
        : this;