@@ -8,111 +8,11 @@ import 'dart:ui' as ui;
8
8
9
9
import 'package:flutter/foundation.dart' ;
10
10
import 'package:js/js.dart' ;
11
- import 'package:js/js_util.dart' as js_util;
12
11
12
+ import '../services/dom.dart' ;
13
13
import 'image_provider.dart' as image_provider;
14
14
import 'image_stream.dart' ;
15
15
16
- /// [DomXMLHttpRequest] interop class.
17
- @JS ()
18
- @staticInterop
19
- class DomXMLHttpRequest {}
20
-
21
- /// [DomXMLHttpRequest] extension.
22
- extension DomXMLHttpRequestExtension on DomXMLHttpRequest {
23
- /// Gets the response.
24
- external dynamic get response;
25
-
26
- /// Gets the response text.
27
- external String ? get responseText;
28
-
29
- /// Gets the response type.
30
- external String get responseType;
31
-
32
- /// Gets the status.
33
- external int ? get status;
34
-
35
- /// Set the response type.
36
- external set responseType (String value);
37
-
38
- /// Set the request header.
39
- external void setRequestHeader (String header, String value);
40
-
41
- /// Open the request.
42
- void open (String method, String url, bool isAsync) => js_util.callMethod (
43
- this , 'open' , < Object > [method, url, isAsync]);
44
-
45
- /// Send the request.
46
- void send () => js_util.callMethod (this , 'send' , < Object > []);
47
-
48
- /// Add event listener.
49
- void addEventListener (String type, DomEventListener ? listener,
50
- [bool ? useCapture]) {
51
- if (listener != null ) {
52
- js_util.callMethod (this , 'addEventListener' ,
53
- < Object > [type, listener, if (useCapture != null ) useCapture]);
54
- }
55
- }
56
- }
57
-
58
- /// Factory function for creating [DomXMLHttpRequest] .
59
- DomXMLHttpRequest createDomXMLHttpRequest () =>
60
- domCallConstructorString ('XMLHttpRequest' , < Object ? > [])!
61
- as DomXMLHttpRequest ;
62
-
63
- /// Type for event listener.
64
- typedef DomEventListener = void Function (DomEvent event);
65
-
66
- /// [DomEvent] interop object.
67
- @JS ()
68
- @staticInterop
69
- class DomEvent {}
70
-
71
- /// [DomEvent] reqiured extension.
72
- extension DomEventExtension on DomEvent {
73
- /// Get the event type.
74
- external String get type;
75
-
76
- /// Initialize an event.
77
- void initEvent (String type, [bool ? bubbles, bool ? cancelable]) =>
78
- js_util.callMethod (this , 'initEvent' , < Object > [
79
- type,
80
- if (bubbles != null ) bubbles,
81
- if (cancelable != null ) cancelable
82
- ]);
83
- }
84
-
85
- /// [DomProgressEvent] interop object.
86
- @JS ()
87
- @staticInterop
88
- class DomProgressEvent extends DomEvent {}
89
-
90
- /// [DomProgressEvent] reqiured extension.
91
- extension DomProgressEventExtension on DomProgressEvent {
92
- /// Amount of work done.
93
- external int ? get loaded;
94
-
95
- /// Total amount of work.
96
- external int ? get total;
97
- }
98
-
99
- /// Gets a constructor from a [String] .
100
- Object ? domGetConstructor (String constructorName) =>
101
- js_util.getProperty (domWindow, constructorName);
102
-
103
- /// Calls a constructor as a [String] .
104
- Object ? domCallConstructorString (String constructorName, List <Object ?> args) {
105
- final Object ? constructor = domGetConstructor (constructorName);
106
- if (constructor == null ) {
107
- return null ;
108
- }
109
- return js_util.callConstructor (constructor, args);
110
- }
111
-
112
- /// The underyling window object.
113
- @JS ('window' )
114
- external Object get domWindow;
115
-
116
16
/// Creates a type for an overridable factory function for testing purposes.
117
17
typedef HttpRequestFactory = DomXMLHttpRequest Function ();
118
18
0 commit comments