-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker_platform_interface] migrate to nnbd #3492
Changes from 8 commits
edf0a36
41212fc
fb198c9
21dd55f
29d8a8a
906de01
8f37451
1161e1f
a9dbc00
66bde58
aa828fb
fcf55a1
be2a278
b548792
3aa1d4b
cde75ee
afb8614
4c32c3d
fd4595c
beca962
9bb9101
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.0.0-nullsafety | ||
|
||
* Migrate to NNBD. | ||
|
||
## 1.1.6 | ||
|
||
* Fix test asset file location. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include: ../../../analysis_options.yaml | ||
|
||
analyzer: | ||
enable-experiment: | ||
- non-nullable | ||
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,14 @@ class MethodChannelImagePicker extends ImagePickerPlatform { | |
MethodChannel get channel => _channel; | ||
|
||
@override | ||
Future<PickedFile> pickImage({ | ||
@required ImageSource source, | ||
double maxWidth, | ||
double maxHeight, | ||
int imageQuality, | ||
Future<PickedFile?> pickImage({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I'm not sure what's the general guideline here. Maybe @blasten knows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quiver appears to be a workaround for the lack of explicit nullability in the type system. With nnbd, I presume that package might get deprecated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess my question would be can the future be completed with error? Why yes or why not? For example, is future.catchError(....)
// or
try {
await future;
} on ... catch {
}
// vs
if (await future == null) {
///
} |
||
required ImageSource source, | ||
double? maxWidth, | ||
double? maxHeight, | ||
int? imageQuality, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
}) async { | ||
String path = await pickImagePath( | ||
String? path = await pickImagePath( | ||
source: source, | ||
maxWidth: maxWidth, | ||
maxHeight: maxHeight, | ||
|
@@ -38,14 +38,13 @@ class MethodChannelImagePicker extends ImagePickerPlatform { | |
} | ||
|
||
@override | ||
Future<String> pickImagePath({ | ||
@required ImageSource source, | ||
double maxWidth, | ||
double maxHeight, | ||
int imageQuality, | ||
Future<String?> pickImagePath({ | ||
required ImageSource source, | ||
double? maxWidth, | ||
double? maxHeight, | ||
int? imageQuality, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
}) { | ||
assert(source != null); | ||
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) { | ||
throw ArgumentError.value( | ||
imageQuality, 'imageQuality', 'must be between 0 and 100'); | ||
|
@@ -72,12 +71,12 @@ class MethodChannelImagePicker extends ImagePickerPlatform { | |
} | ||
|
||
@override | ||
Future<PickedFile> pickVideo({ | ||
@required ImageSource source, | ||
Future<PickedFile?> pickVideo({ | ||
required ImageSource source, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
Duration maxDuration, | ||
Duration? maxDuration, | ||
}) async { | ||
String path = await pickVideoPath( | ||
String? path = await pickVideoPath( | ||
source: source, | ||
maxDuration: maxDuration, | ||
preferredCameraDevice: preferredCameraDevice, | ||
|
@@ -86,12 +85,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform { | |
} | ||
|
||
@override | ||
Future<String> pickVideoPath({ | ||
@required ImageSource source, | ||
Future<String?> pickVideoPath({ | ||
required ImageSource source, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
Duration maxDuration, | ||
Duration? maxDuration, | ||
}) { | ||
assert(source != null); | ||
return _channel.invokeMethod<String>( | ||
'pickVideo', | ||
<String, dynamic>{ | ||
|
@@ -104,7 +102,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { | |
|
||
@override | ||
Future<LostData> retrieveLostData() async { | ||
final Map<String, dynamic> result = | ||
final Map<String, dynamic>? result = | ||
await _channel.invokeMapMethod<String, dynamic>('retrieve'); | ||
|
||
if (result == null) { | ||
|
@@ -113,23 +111,23 @@ class MethodChannelImagePicker extends ImagePickerPlatform { | |
|
||
assert(result.containsKey('path') ^ result.containsKey('errorCode')); | ||
|
||
final String type = result['type']; | ||
final String? type = result['type']; | ||
assert(type == kTypeImage || type == kTypeVideo); | ||
|
||
RetrieveType retrieveType; | ||
RetrieveType? retrieveType; | ||
if (type == kTypeImage) { | ||
retrieveType = RetrieveType.image; | ||
} else if (type == kTypeVideo) { | ||
retrieveType = RetrieveType.video; | ||
} | ||
|
||
PlatformException exception; | ||
PlatformException? exception; | ||
if (result.containsKey('errorCode')) { | ||
exception = PlatformException( | ||
code: result['errorCode'], message: result['errorMessage']); | ||
} | ||
|
||
final String path = result['path']; | ||
final String? path = result['path']; | ||
|
||
return LostData( | ||
file: path != null ? PickedFile(path) : null, | ||
|
@@ -141,31 +139,31 @@ class MethodChannelImagePicker extends ImagePickerPlatform { | |
@override | ||
// ignore: deprecated_member_use_from_same_package | ||
Future<LostDataResponse> retrieveLostDataAsDartIoFile() async { | ||
final Map<String, dynamic> result = | ||
final Map<String, dynamic>? result = | ||
await _channel.invokeMapMethod<String, dynamic>('retrieve'); | ||
if (result == null) { | ||
// ignore: deprecated_member_use_from_same_package | ||
return LostDataResponse.empty(); | ||
} | ||
assert(result.containsKey('path') ^ result.containsKey('errorCode')); | ||
|
||
final String type = result['type']; | ||
final String? type = result['type']; | ||
assert(type == kTypeImage || type == kTypeVideo); | ||
|
||
RetrieveType retrieveType; | ||
RetrieveType? retrieveType; | ||
if (type == kTypeImage) { | ||
retrieveType = RetrieveType.image; | ||
} else if (type == kTypeVideo) { | ||
retrieveType = RetrieveType.video; | ||
} | ||
|
||
PlatformException exception; | ||
PlatformException? exception; | ||
if (result.containsKey('errorCode')) { | ||
exception = PlatformException( | ||
code: result['errorCode'], message: result['errorMessage']); | ||
} | ||
|
||
final String path = result['path']; | ||
final String? path = result['path']; | ||
|
||
// ignore: deprecated_member_use_from_same_package | ||
return LostDataResponse( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,11 +61,11 @@ abstract class ImagePickerPlatform extends PlatformInterface { | |
/// In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost | ||
/// in this call. You can then call [retrieveLostDataAsDartIoFile] when your app relaunches to retrieve the lost data. | ||
@Deprecated('Use pickImage instead.') | ||
Future<String> pickImagePath({ | ||
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@required ImageSource source, | ||
double maxWidth, | ||
double maxHeight, | ||
int imageQuality, | ||
Future<String?> pickImagePath({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docs for this method does not specify what to do when the future returns |
||
required ImageSource source, | ||
double? maxWidth, | ||
double? maxHeight, | ||
int? imageQuality, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
}) { | ||
throw UnimplementedError('legacyPickImage() has not been implemented.'); | ||
|
@@ -86,10 +86,10 @@ abstract class ImagePickerPlatform extends PlatformInterface { | |
/// In Android, the MainActivity can be destroyed for various fo reasons. If that happens, the result will be lost | ||
/// in this call. You can then call [retrieveLostDataAsDartIoFile] when your app relaunches to retrieve the lost data. | ||
@Deprecated('Use pickVideo instead.') | ||
Future<String> pickVideoPath({ | ||
@required ImageSource source, | ||
Future<String?> pickVideoPath({ | ||
required ImageSource source, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
Duration maxDuration, | ||
Duration? maxDuration, | ||
}) { | ||
throw UnimplementedError('pickVideoPath() has not been implemented.'); | ||
} | ||
|
@@ -141,11 +141,11 @@ abstract class ImagePickerPlatform extends PlatformInterface { | |
/// | ||
/// In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost | ||
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data. | ||
Future<PickedFile> pickImage({ | ||
@required ImageSource source, | ||
double maxWidth, | ||
double maxHeight, | ||
int imageQuality, | ||
Future<PickedFile?> pickImage({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. Added docs to explain the null value. |
||
required ImageSource source, | ||
double? maxWidth, | ||
double? maxHeight, | ||
int? imageQuality, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
}) { | ||
throw UnimplementedError('pickImage() has not been implemented.'); | ||
|
@@ -165,10 +165,10 @@ abstract class ImagePickerPlatform extends PlatformInterface { | |
/// | ||
/// In Android, the MainActivity can be destroyed for various fo reasons. If that happens, the result will be lost | ||
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data. | ||
Future<PickedFile> pickVideo({ | ||
@required ImageSource source, | ||
Future<PickedFile?> pickVideo({ | ||
cyanglaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
required ImageSource source, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
Duration maxDuration, | ||
Duration? maxDuration, | ||
}) { | ||
throw UnimplementedError('pickVideo() has not been implemented.'); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,7 @@ abstract class PickedFileBase { | |
/// If `end` is present, only up to byte-index `end` will be read. Otherwise, until end of file. | ||
/// | ||
/// In order to make sure that system resources are freed, the stream must be read to completion or the subscription on the stream must be cancelled. | ||
Stream<Uint8List> openRead([int start, int end]) { | ||
Stream<Uint8List> openRead([int? start, int? end]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be named parameters instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These follow the File API. Anyway, this code will eventually be removed (it's available, and reusable in the cross_file package now) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's unrelated to NNBD and I'd prefer not to break the API. Also it's going to be removed soon (probably the very next patch), let's not introduce 2 consecutive breaking changes for people to migrate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sgtm |
||
throw UnimplementedError('openRead() has not been implemented.'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ class LostData { | |
/// The file that was lost in a previous [pickImage] or [pickVideo] call due to MainActivity being destroyed. | ||
/// | ||
/// Can be null if [exception] exists. | ||
final PickedFile file; | ||
final PickedFile? file; | ||
|
||
/// The exception of the last [pickImage] or [pickVideo]. | ||
/// | ||
|
@@ -40,10 +40,10 @@ class LostData { | |
/// You should handle this exception as if the [pickImage] or [pickVideo] got an exception when the MainActivity was not destroyed. | ||
/// | ||
/// Note that it is not the exception that caused the destruction of the MainActivity. | ||
final PlatformException exception; | ||
final PlatformException? exception; | ||
|
||
/// Can either be [RetrieveType.image] or [RetrieveType.video]; | ||
final RetrieveType type; | ||
final RetrieveType? type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the docs doesn't say null though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
bool _empty = false; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,21 @@ description: A common platform interface for the image_picker plugin. | |
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker_platform_interface | ||
# NOTE: We strongly prefer non-breaking changes, even at the expense of a | ||
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes | ||
version: 1.1.6 | ||
version: 2.0.0-nullsafety | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
meta: ^1.1.8 | ||
http: ^0.12.1 | ||
plugin_platform_interface: ^1.0.2 | ||
meta: ^1.3.0-nullsafety.6 | ||
http: ^0.13.0-nullsafety.0 | ||
plugin_platform_interface: ^1.1.0-nullsafety.2 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
mockito: ^4.1.1 | ||
pedantic: ^1.8.0+1 | ||
mockito: ^5.0.0-nullsafety.5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked, and mockito doesn't seem to be used in this package. It can probably be removed :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
pedantic: ^1.10.0-nullsafety.3 | ||
|
||
environment: | ||
sdk: ">=2.5.0 <3.0.0" | ||
sdk: ">=2.12.0-0 <3.0.0" | ||
cyanglaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
flutter: ">=1.10.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,7 +312,7 @@ void main() { | |
// ignore: deprecated_member_use_from_same_package | ||
final LostData response = await picker.retrieveLostData(); | ||
expect(response.type, RetrieveType.image); | ||
expect(response.file.path, '/example/path'); | ||
expect(response.file?.path, '/example/path'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. check |
||
}); | ||
|
||
test('retrieveLostData get error response', () async { | ||
|
@@ -326,8 +326,8 @@ void main() { | |
// ignore: deprecated_member_use_from_same_package | ||
final LostData response = await picker.retrieveLostData(); | ||
expect(response.type, RetrieveType.video); | ||
expect(response.exception.code, 'test_error_code'); | ||
expect(response.exception.message, 'test_error_message'); | ||
expect(response.exception?.code, 'test_error_code'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: check that |
||
expect(response.exception?.message, 'test_error_message'); | ||
}); | ||
|
||
test('retrieveLostData get null response', () async { | ||
|
Uh oh!
There was an error while loading. Please reload this page.