/// Created by Haoyi on 4/28/21

part of "converts.dart";

class ColorStringConvert implements JsonConverter<Color, String> {
  final Color defaultColor;

  const ColorStringConvert({required this.defaultColor});

  @override
  Color fromJson(String json) {
    try {
      return ColorUtils.toColor(json);
    } catch (error) {
      return defaultColor;
    }
  }

  @override
  String toJson(Color color) {
    return "#${color.value.toRadixString(16)}";
  }
}
