fetchTarget function

UrlTarget? fetchTarget(
  1. List<UrlTarget> targets,
  2. Uri url
)

Fetches target based on URL

Implementation

UrlTarget? fetchTarget(List<UrlTarget> targets, Uri url) {
  for (final t in targets) {
    for (final urlPart in t.where) {
      if (urlPart == "/") {
        return t;
      } else if (url.path.contains(urlPart)) {
        return t;
      } else {
        final pattern = RegExp(urlPart);
        if (pattern.hasMatch(url.toString())) {
          return t;
        }
      }
    }
  }
  return null;
}