Filter hasAllowedScheme(String attribute, Iterable<String> schemes)

Returns a Filter that can test if the path in attribute has one of the schemes.

The Filter will only return true if:

  • the attribute exists;
  • contains a non-null value;
  • that is a valid uri;
  • and the scheme of that uri is blank or listed in schemes.

Source

static Filter hasAllowedScheme(String attribute, Iterable<String> schemes) {
  var allowed = new List.from(schemes);
  return (t, o) {
    var uri = o[attribute];
    if (uri == null || !isValid(uri)) {
      return false;
    }
    var scheme = Uri.parse(uri).scheme;
    return scheme.isEmpty || allowed.contains(scheme);
  };
}