networkSourceMatcher function

CustomRenderMatcher networkSourceMatcher({
  1. List<String> schemas = const ["https", "http"],
  2. List<String>? domains,
  3. String? extension,
})

Implementation

CustomRenderMatcher networkSourceMatcher({
  List<String> schemas = const ["https", "http"],
  List<String>? domains,
  String? extension,
}) {
  //...
  return (context) {
    final blu = context.tree.element?.attributes;
    if (blu == null) return false;
    final attr = _src(context.tree.element!.attributes.cast());
    if (attr == null) return false;
    if (context.tree.element?.attributes.cast() == null ||
        _src(context.tree.element!.attributes.cast()) == null) return false;
    try {
      final src = Uri.parse(_src(context.tree.element!.attributes.cast())!);
      return schemas.contains(src.scheme) &&
          (domains == null || domains.contains(src.host)) &&
          (extension == null || src.path.endsWith(".$extension"));
    } catch (e) {
      return false;
    }
  };
}