@@ -13,14 +13,14 @@ final String _kAcceptVideoMimeType = 'video/3gpp,video/x-m4v,video/mp4,video/*';
13
13
///
14
14
/// This class implements the `package:image_picker` functionality for the web.
15
15
class ImagePickerPlugin extends ImagePickerPlatform {
16
- final ImagePickerPluginTestOverrides _overrides;
16
+ final ImagePickerPluginTestOverrides ? _overrides;
17
17
bool get _hasOverrides => _overrides != null ;
18
18
19
- html.Element _target;
19
+ late html.Element _target;
20
20
21
21
/// A constructor that allows tests to override the function that creates file inputs.
22
22
ImagePickerPlugin ({
23
- @visibleForTesting ImagePickerPluginTestOverrides overrides,
23
+ @visibleForTesting ImagePickerPluginTestOverrides ? overrides,
24
24
}) : _overrides = overrides {
25
25
_target = _ensureInitialized (_kImagePickerInputsDomId);
26
26
}
@@ -32,23 +32,23 @@ class ImagePickerPlugin extends ImagePickerPlatform {
32
32
33
33
@override
34
34
Future <PickedFile > pickImage ({
35
- @ required ImageSource source,
36
- double maxWidth,
37
- double maxHeight,
38
- int imageQuality,
35
+ required ImageSource source,
36
+ double ? maxWidth,
37
+ double ? maxHeight,
38
+ int ? imageQuality,
39
39
CameraDevice preferredCameraDevice = CameraDevice .rear,
40
40
}) {
41
- String capture = computeCaptureAttribute (source, preferredCameraDevice);
41
+ String ? capture = computeCaptureAttribute (source, preferredCameraDevice);
42
42
return pickFile (accept: _kAcceptImageMimeType, capture: capture);
43
43
}
44
44
45
45
@override
46
46
Future <PickedFile > pickVideo ({
47
- @ required ImageSource source,
47
+ required ImageSource source,
48
48
CameraDevice preferredCameraDevice = CameraDevice .rear,
49
- Duration maxDuration,
49
+ Duration ? maxDuration,
50
50
}) {
51
- String capture = computeCaptureAttribute (source, preferredCameraDevice);
51
+ String ? capture = computeCaptureAttribute (source, preferredCameraDevice);
52
52
return pickFile (accept: _kAcceptVideoMimeType, capture: capture);
53
53
}
54
54
@@ -59,10 +59,10 @@ class ImagePickerPlugin extends ImagePickerPlatform {
59
59
/// See https://caniuse.com/#feat=html-media-capture
60
60
@visibleForTesting
61
61
Future <PickedFile > pickFile ({
62
- String accept,
63
- String capture,
62
+ String ? accept,
63
+ String ? capture,
64
64
}) {
65
- html.FileUploadInputElement input = createInputElement (accept, capture);
65
+ html.FileUploadInputElement input = createInputElement (accept, capture) as html. FileUploadInputElement ;
66
66
_injectAndActivate (input);
67
67
return _getSelectedFile (input);
68
68
}
@@ -73,25 +73,25 @@ class ImagePickerPlugin extends ImagePickerPlatform {
73
73
///
74
74
/// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#capture
75
75
@visibleForTesting
76
- String computeCaptureAttribute (ImageSource source, CameraDevice device) {
76
+ String ? computeCaptureAttribute (ImageSource source, CameraDevice device) {
77
77
if (source == ImageSource .camera) {
78
78
return (device == CameraDevice .front) ? 'user' : 'environment' ;
79
79
}
80
80
return null ;
81
81
}
82
82
83
- html.File _getFileFromInput (html.FileUploadInputElement input) {
83
+ html.File ? _getFileFromInput (html.FileUploadInputElement ? input) {
84
84
if (_hasOverrides) {
85
- return _overrides.getFileFromInput (input);
85
+ return _overrides! .getFileFromInput (input);
86
86
}
87
87
return input? .files? .first;
88
88
}
89
89
90
90
/// Handles the OnChange event from a FileUploadInputElement object
91
91
/// Returns the objectURL of the selected file.
92
- String _handleOnChangeEvent (html.Event event) {
93
- final html.FileUploadInputElement input = event? .target;
94
- final html.File file = _getFileFromInput (input);
92
+ String ? _handleOnChangeEvent (html.Event event) {
93
+ final html.FileUploadInputElement ? input = event.target as html. FileUploadInputElement ;
94
+ final html.File ? file = _getFileFromInput (input);
95
95
96
96
if (file != null ) {
97
97
return html.Url .createObjectUrl (file);
@@ -106,7 +106,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
106
106
input.onChange.first.then ((event) {
107
107
final objectUrl = _handleOnChangeEvent (event);
108
108
if (! _completer.isCompleted) {
109
- _completer.complete (PickedFile (objectUrl));
109
+ _completer.complete (PickedFile (objectUrl! ));
110
110
}
111
111
});
112
112
input.onError.first.then ((event) {
@@ -127,7 +127,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
127
127
final html.Element targetElement =
128
128
html.Element .tag ('flt-image-picker-inputs' )..id = id;
129
129
130
- html.querySelector ('body' ).children.add (targetElement);
130
+ html.querySelector ('body' )! .children.add (targetElement);
131
131
target = targetElement;
132
132
}
133
133
return target;
@@ -136,9 +136,9 @@ class ImagePickerPlugin extends ImagePickerPlatform {
136
136
/// Creates an input element that accepts certain file types, and
137
137
/// allows to `capture` from the device's cameras (where supported)
138
138
@visibleForTesting
139
- html.Element createInputElement (String accept, String capture) {
139
+ html.Element createInputElement (String ? accept, String ? capture) {
140
140
if (_hasOverrides) {
141
- return _overrides.createInputElement (accept, capture);
141
+ return _overrides! .createInputElement (accept, capture);
142
142
}
143
143
144
144
html.Element element = html.FileUploadInputElement ()..accept = accept;
@@ -162,22 +162,22 @@ class ImagePickerPlugin extends ImagePickerPlatform {
162
162
/// A function that creates a file input with the passed in `accept` and `capture` attributes.
163
163
@visibleForTesting
164
164
typedef OverrideCreateInputFunction = html.Element Function (
165
- String accept,
166
- String capture,
165
+ String ? accept,
166
+ String ? capture,
167
167
);
168
168
169
169
/// A function that extracts a [html.File] from the file `input` passed in.
170
170
@visibleForTesting
171
171
typedef OverrideExtractFilesFromInputFunction = html.File Function (
172
- html.Element input,
172
+ html.Element ? input,
173
173
);
174
174
175
175
/// Overrides for some of the functionality above.
176
176
@visibleForTesting
177
177
class ImagePickerPluginTestOverrides {
178
178
/// Override the creation of the input element.
179
- OverrideCreateInputFunction createInputElement;
179
+ late OverrideCreateInputFunction createInputElement;
180
180
181
181
/// Override the extraction of the selected file from an input element.
182
- OverrideExtractFilesFromInputFunction getFileFromInput;
182
+ late OverrideExtractFilesFromInputFunction getFileFromInput;
183
183
}
0 commit comments