Hit | Total | Coverage | |
---|---|---|---|
Lines | 5 | 6 | 83.3% |
Functions | 0 | 0 | - |
Branches | 0 | 0 | - |
Line | Branch | Hits | Source code |
---|---|---|---|
1 | import 'dart:js_interop'; |
||
2 |
|
||
3 | import 'package:web/web.dart' as web; |
||
4 |
|
||
5 | @JS() |
||
6 | external JSPromise<web.Response> fetch(JSAny resource, [JSAny? options]); |
||
7 |
|
||
8 | class UriChecker { |
||
9 | UriChecker._(); |
||
10 |
|
||
11 | static const headers = {'method': 'HEAD'}; |
||
12 |
|
||
13 | 2 | static Future<bool> exists(Uri url) async { |
|
14 | 2 | if (url.isScheme('data')) return true; |
|
15 | try { |
||
16 | 2 | final res = await fetch(url.toString().toJS, headers.jsify()).toDart; |
|
17 | 2 | return res.ok && (200 <= res.status) && (res.status < 300); |
|
18 | } catch (_) { |
||
19 | 0 | return false; |
|
20 | } |
||
21 | 2 | } |
|
22 | } |