@@ -13,14 +13,14 @@ final String _kAcceptVideoMimeType = 'video/3gpp,video/x-m4v,video/mp4,video/*';
1313///
1414/// This class implements the `package:image_picker` functionality for the web.
1515class ImagePickerPlugin extends ImagePickerPlatform {
16- final ImagePickerPluginTestOverrides _overrides;
16+ final ImagePickerPluginTestOverrides ? _overrides;
1717 bool get _hasOverrides => _overrides != null ;
1818
19- html.Element _target;
19+ late html.Element _target;
2020
2121 /// A constructor that allows tests to override the function that creates file inputs.
2222 ImagePickerPlugin ({
23- @visibleForTesting ImagePickerPluginTestOverrides overrides,
23+ @visibleForTesting ImagePickerPluginTestOverrides ? overrides,
2424 }) : _overrides = overrides {
2525 _target = _ensureInitialized (_kImagePickerInputsDomId);
2626 }
@@ -32,23 +32,23 @@ class ImagePickerPlugin extends ImagePickerPlatform {
3232
3333 @override
3434 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,
3939 CameraDevice preferredCameraDevice = CameraDevice .rear,
4040 }) {
41- String capture = computeCaptureAttribute (source, preferredCameraDevice);
41+ String ? capture = computeCaptureAttribute (source, preferredCameraDevice);
4242 return pickFile (accept: _kAcceptImageMimeType, capture: capture);
4343 }
4444
4545 @override
4646 Future <PickedFile > pickVideo ({
47- @ required ImageSource source,
47+ required ImageSource source,
4848 CameraDevice preferredCameraDevice = CameraDevice .rear,
49- Duration maxDuration,
49+ Duration ? maxDuration,
5050 }) {
51- String capture = computeCaptureAttribute (source, preferredCameraDevice);
51+ String ? capture = computeCaptureAttribute (source, preferredCameraDevice);
5252 return pickFile (accept: _kAcceptVideoMimeType, capture: capture);
5353 }
5454
@@ -59,10 +59,10 @@ class ImagePickerPlugin extends ImagePickerPlatform {
5959 /// See https://caniuse.com/#feat=html-media-capture
6060 @visibleForTesting
6161 Future <PickedFile > pickFile ({
62- String accept,
63- String capture,
62+ String ? accept,
63+ String ? capture,
6464 }) {
65- html.FileUploadInputElement input = createInputElement (accept, capture);
65+ html.FileUploadInputElement input = createInputElement (accept, capture) as html. FileUploadInputElement ;
6666 _injectAndActivate (input);
6767 return _getSelectedFile (input);
6868 }
@@ -73,25 +73,25 @@ class ImagePickerPlugin extends ImagePickerPlatform {
7373 ///
7474 /// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#capture
7575 @visibleForTesting
76- String computeCaptureAttribute (ImageSource source, CameraDevice device) {
76+ String ? computeCaptureAttribute (ImageSource source, CameraDevice device) {
7777 if (source == ImageSource .camera) {
7878 return (device == CameraDevice .front) ? 'user' : 'environment' ;
7979 }
8080 return null ;
8181 }
8282
83- html.File _getFileFromInput (html.FileUploadInputElement input) {
83+ html.File ? _getFileFromInput (html.FileUploadInputElement ? input) {
8484 if (_hasOverrides) {
85- return _overrides.getFileFromInput (input);
85+ return _overrides! .getFileFromInput (input);
8686 }
8787 return input? .files? .first;
8888 }
8989
9090 /// Handles the OnChange event from a FileUploadInputElement object
9191 /// 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);
9595
9696 if (file != null ) {
9797 return html.Url .createObjectUrl (file);
@@ -106,7 +106,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
106106 input.onChange.first.then ((event) {
107107 final objectUrl = _handleOnChangeEvent (event);
108108 if (! _completer.isCompleted) {
109- _completer.complete (PickedFile (objectUrl));
109+ _completer.complete (PickedFile (objectUrl! ));
110110 }
111111 });
112112 input.onError.first.then ((event) {
@@ -127,7 +127,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
127127 final html.Element targetElement =
128128 html.Element .tag ('flt-image-picker-inputs' )..id = id;
129129
130- html.querySelector ('body' ).children.add (targetElement);
130+ html.querySelector ('body' )! .children.add (targetElement);
131131 target = targetElement;
132132 }
133133 return target;
@@ -136,9 +136,9 @@ class ImagePickerPlugin extends ImagePickerPlatform {
136136 /// Creates an input element that accepts certain file types, and
137137 /// allows to `capture` from the device's cameras (where supported)
138138 @visibleForTesting
139- html.Element createInputElement (String accept, String capture) {
139+ html.Element createInputElement (String ? accept, String ? capture) {
140140 if (_hasOverrides) {
141- return _overrides.createInputElement (accept, capture);
141+ return _overrides! .createInputElement (accept, capture);
142142 }
143143
144144 html.Element element = html.FileUploadInputElement ()..accept = accept;
@@ -162,22 +162,22 @@ class ImagePickerPlugin extends ImagePickerPlatform {
162162/// A function that creates a file input with the passed in `accept` and `capture` attributes.
163163@visibleForTesting
164164typedef OverrideCreateInputFunction = html.Element Function (
165- String accept,
166- String capture,
165+ String ? accept,
166+ String ? capture,
167167);
168168
169169/// A function that extracts a [html.File] from the file `input` passed in.
170170@visibleForTesting
171171typedef OverrideExtractFilesFromInputFunction = html.File Function (
172- html.Element input,
172+ html.Element ? input,
173173);
174174
175175/// Overrides for some of the functionality above.
176176@visibleForTesting
177177class ImagePickerPluginTestOverrides {
178178 /// Override the creation of the input element.
179- OverrideCreateInputFunction createInputElement;
179+ late OverrideCreateInputFunction createInputElement;
180180
181181 /// Override the extraction of the selected file from an input element.
182- OverrideExtractFilesFromInputFunction getFileFromInput;
182+ late OverrideExtractFilesFromInputFunction getFileFromInput;
183183}
0 commit comments