@@ -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,11 @@ 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 =
66+ createInputElement (accept, capture) as html.FileUploadInputElement ;
6667 _injectAndActivate (input);
6768 return _getSelectedFile (input);
6869 }
@@ -73,25 +74,26 @@ class ImagePickerPlugin extends ImagePickerPlatform {
7374 ///
7475 /// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#capture
7576 @visibleForTesting
76- String computeCaptureAttribute (ImageSource source, CameraDevice device) {
77+ String ? computeCaptureAttribute (ImageSource source, CameraDevice device) {
7778 if (source == ImageSource .camera) {
7879 return (device == CameraDevice .front) ? 'user' : 'environment' ;
7980 }
8081 return null ;
8182 }
8283
83- html.File _getFileFromInput (html.FileUploadInputElement input) {
84+ html.File ? _getFileFromInput (html.FileUploadInputElement input) {
8485 if (_hasOverrides) {
85- return _overrides.getFileFromInput (input);
86+ return _overrides! .getFileFromInput (input);
8687 }
87- return input? .files? .first;
88+ return input.files? .first;
8889 }
8990
9091 /// Handles the OnChange event from a FileUploadInputElement object
9192 /// 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);
93+ String ? _handleOnChangeEvent (html.Event event) {
94+ final html.FileUploadInputElement input =
95+ event.target as html.FileUploadInputElement ;
96+ final html.File ? file = _getFileFromInput (input);
9597
9698 if (file != null ) {
9799 return html.Url .createObjectUrl (file);
@@ -105,7 +107,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
105107 // Observe the input until we can return something
106108 input.onChange.first.then ((event) {
107109 final objectUrl = _handleOnChangeEvent (event);
108- if (! _completer.isCompleted) {
110+ if (! _completer.isCompleted && objectUrl != null ) {
109111 _completer.complete (PickedFile (objectUrl));
110112 }
111113 });
@@ -127,7 +129,7 @@ class ImagePickerPlugin extends ImagePickerPlatform {
127129 final html.Element targetElement =
128130 html.Element .tag ('flt-image-picker-inputs' )..id = id;
129131
130- html.querySelector ('body' ).children.add (targetElement);
132+ html.querySelector ('body' )! .children.add (targetElement);
131133 target = targetElement;
132134 }
133135 return target;
@@ -136,9 +138,9 @@ class ImagePickerPlugin extends ImagePickerPlatform {
136138 /// Creates an input element that accepts certain file types, and
137139 /// allows to `capture` from the device's cameras (where supported)
138140 @visibleForTesting
139- html.Element createInputElement (String accept, String capture) {
141+ html.Element createInputElement (String ? accept, String ? capture) {
140142 if (_hasOverrides) {
141- return _overrides.createInputElement (accept, capture);
143+ return _overrides! .createInputElement (accept, capture);
142144 }
143145
144146 html.Element element = html.FileUploadInputElement ()..accept = accept;
@@ -162,22 +164,22 @@ class ImagePickerPlugin extends ImagePickerPlatform {
162164/// A function that creates a file input with the passed in `accept` and `capture` attributes.
163165@visibleForTesting
164166typedef OverrideCreateInputFunction = html.Element Function (
165- String accept,
166- String capture,
167+ String ? accept,
168+ String ? capture,
167169);
168170
169171/// A function that extracts a [html.File] from the file `input` passed in.
170172@visibleForTesting
171173typedef OverrideExtractFilesFromInputFunction = html.File Function (
172- html.Element input,
174+ html.Element ? input,
173175);
174176
175177/// Overrides for some of the functionality above.
176178@visibleForTesting
177179class ImagePickerPluginTestOverrides {
178180 /// Override the creation of the input element.
179- OverrideCreateInputFunction createInputElement;
181+ late OverrideCreateInputFunction createInputElement;
180182
181183 /// Override the extraction of the selected file from an input element.
182- OverrideExtractFilesFromInputFunction getFileFromInput;
184+ late OverrideExtractFilesFromInputFunction getFileFromInput;
183185}
0 commit comments