customError method

String customError(
  1. String key,
  2. dynamic value
)

Renders the given custom error.

Implementation

String customError(String key, value) {
  if (!customErrorMessages.containsKey(key)) {
    throw ArgumentError("No custom error message registered for '$key'.");
  }

  var msg = customErrorMessages[key];

  if (msg is String) {
    return msg.replaceAll('{{value}}', value.toString());
  } else if (msg is CustomErrorMessageFunction) {
    return msg(value);
  }

  throw ArgumentError("Invalid custom error message '$key': $msg");
}