generateColor function

Color? generateColor(
  1. String type,
  2. String text
)

Implementation

Color? generateColor(String type, String text) {
  Color? color;
  if (type == "text") {
    if (text.contains("#")) {
      try {
        color = Color(int.parse(text.substring(1).padLeft(8, "FF"), radix: 16));
      } catch (err) {
        color = Colors.white;
        print(err);
      }
    }
  } else {
    if (text.contains("#")) {
      try {
        color = Color(int.parse(text.substring(1).padLeft(8, "FF"), radix: 16));
      } catch (err) {
        color = Colors.blueAccent;
        print(err);
      }
    } else {
      color = Colors.blueAccent;
    }
  }
  return color;
}