getColorOrNull method

Color? getColorOrNull(
  1. String name, {
  2. Color? defaults,
})

Implementation

Color? getColorOrNull(String name, {Color? defaults}) {
  final tiledColor = getStringOrNull(name);

  // Tiled colors are stored as either ARGB or RGB hex values, so we can
  // parse them as hex numbers with a little coercing.
  int? colorValue;
  if (tiledColor?.length == 7) {
    // parse '#rrbbgg'  as hex '0xaarrggbb' with the alpha channel on full
    colorValue = int.tryParse(tiledColor!.replaceFirst('#', '0xff'));
  } else if (tiledColor?.length == 9) {
    // parse '#aarrbbgg'  as hex '0xaarrggbb'
    colorValue = int.tryParse(tiledColor!.replaceFirst('#', '0x'));
  }

  if (colorValue != null) {
    return Color(colorValue);
  } else {
    return defaults;
  }
}