Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 9082758

Browse files
rebase and fix conflicts
1 parent 09d0f79 commit 9082758

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

packages/image_picker/image_picker_for_web/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 1.0.0-nullsafety
2+
3+
* Migrate to null safety.
14
# 0.1.0+3
25

36
* Update Flutter SDK constraint.

packages/image_picker/image_picker_for_web/lib/image_picker_for_web.dart

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1515
class 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
164164
typedef 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
171171
typedef OverrideExtractFilesFromInputFunction = html.File Function(
172-
html.Element input,
172+
html.Element? input,
173173
);
174174

175175
/// Overrides for some of the functionality above.
176176
@visibleForTesting
177177
class 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
}

packages/image_picker/image_picker_for_web/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/i
44
# 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump
55
# the version to 2.0.0.
66
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
7-
version: 0.1.0+3
7+
version: 1.0.0-nullsafety
88

99
flutter:
1010
plugin:
@@ -14,19 +14,19 @@ flutter:
1414
fileName: image_picker_for_web.dart
1515

1616
dependencies:
17-
image_picker_platform_interface: ^1.1.0
17+
image_picker_platform_interface: ^2.0.0-nullsafety
1818
flutter:
1919
sdk: flutter
2020
flutter_web_plugins:
2121
sdk: flutter
22-
meta: ^1.1.7
23-
js: ^0.6.0
22+
meta: ^1.3.0-nullsafety.6
23+
js: ^0.6.3-nullsafety.3
2424

2525
dev_dependencies:
2626
flutter_test:
2727
sdk: flutter
28-
pedantic: ^1.8.0
28+
pedantic: ^1.10.0
2929

3030
environment:
31-
sdk: ">=2.5.0 <3.0.0"
31+
sdk: ">=2.12.0-0 <3.0.0"
3232
flutter: ">=1.10.0"

packages/image_picker/image_picker_for_web/test/image_picker_for_web_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import 'package:image_picker_for_web/image_picker_for_web.dart';
1313
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
1414

1515
final String expectedStringContents = "Hello, world!";
16-
final Uint8List bytes = utf8.encode(expectedStringContents);
16+
final Uint8List bytes = utf8.encode(expectedStringContents) as Uint8List;
1717
final html.File textFile = html.File([bytes], "hello.txt");
1818

1919
void main() {
2020
// Under test...
21-
ImagePickerPlugin plugin;
21+
late ImagePickerPlugin plugin;
2222

2323
setUp(() {
2424
plugin = ImagePickerPlugin();

0 commit comments

Comments
 (0)