-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker_platform_interface] migrate to nnbd #3492
Changes from 16 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 |
---|---|---|
|
@@ -39,80 +39,6 @@ abstract class ImagePickerPlatform extends PlatformInterface { | |
_instance = instance; | ||
} | ||
|
||
/// Returns a [String] containing a path to the image that was picked. | ||
/// | ||
/// The `source` argument controls where the image comes from. This can | ||
/// be either [ImageSource.camera] or [ImageSource.gallery]. | ||
/// | ||
/// If specified, the image will be at most `maxWidth` wide and | ||
/// `maxHeight` tall. Otherwise the image will be returned at it's | ||
/// original width and height. | ||
/// | ||
/// The `imageQuality` argument modifies the quality of the image, ranging from 0-100 | ||
/// where 100 is the original/max quality. If `imageQuality` is null, the image with | ||
/// the original quality will be returned. Compression is only supported for certain | ||
/// image types such as JPEG and on Android PNG and WebP, too. If compression is not supported for the image that is picked, | ||
/// a warning message will be logged. | ||
/// | ||
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera]. | ||
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device. | ||
/// Defaults to [CameraDevice.rear]. | ||
/// | ||
/// 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({ | ||
@required ImageSource source, | ||
double maxWidth, | ||
double maxHeight, | ||
int imageQuality, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
}) { | ||
throw UnimplementedError('legacyPickImage() has not been implemented.'); | ||
} | ||
|
||
/// Returns a [String] containing a path to the video that was picked. | ||
/// | ||
/// The [source] argument controls where the video comes from. This can | ||
/// be either [ImageSource.camera] or [ImageSource.gallery]. | ||
/// | ||
/// The [maxDuration] argument specifies the maximum duration of the captured video. If no [maxDuration] is specified, | ||
/// the maximum duration will be infinite. | ||
/// | ||
/// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera]. | ||
/// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device. | ||
/// Defaults to [CameraDevice.rear]. | ||
/// | ||
/// 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, | ||
CameraDevice preferredCameraDevice = CameraDevice.rear, | ||
Duration maxDuration, | ||
}) { | ||
throw UnimplementedError('pickVideoPath() has not been implemented.'); | ||
} | ||
|
||
/// Retrieve the lost image file when [pickImagePath] or [pickVideoPath] failed because the MainActivity is destroyed. (Android only) | ||
/// | ||
/// Image or video can be lost if the MainActivity is destroyed. And there is no guarantee that the MainActivity is always alive. | ||
/// Call this method to retrieve the lost data and process the data according to your APP's business logic. | ||
/// | ||
/// Returns a [LostDataResponse] if successfully retrieved the lost data. The [LostDataResponse] can represent either a | ||
/// successful image/video selection, or a failure. | ||
/// | ||
/// Calling this on a non-Android platform will throw [UnimplementedError] exception. | ||
/// | ||
/// See also: | ||
/// * [LostDataResponse], for what's included in the response. | ||
/// * [Android Activity Lifecycle](https://developer.android.com/reference/android/app/Activity.html), for more information on MainActivity destruction. | ||
@Deprecated('Use retrieveLostData instead.') | ||
Future<LostDataResponse> retrieveLostDataAsDartIoFile() { | ||
throw UnimplementedError( | ||
'retrieveLostDataAsDartIoFile() has not been implemented.'); | ||
} | ||
|
||
// Next version of the API. | ||
|
||
/// Returns a [PickedFile] with the image that was picked. | ||
|
@@ -141,11 +67,13 @@ 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, | ||
/// | ||
/// If no images were picked, the return value is null. | ||
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 +93,12 @@ 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, | ||
/// | ||
/// If no images were picked, the return value is null. | ||
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,12 @@ 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; | ||
/// | ||
/// If the lost data is empty, this will be null. | ||
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to use
Optional
, instead of nullable here?Future<Optional<PickedFile>>
? I've seen Optional classes inpackage:quiver
docs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
So
Future<PickedFile?>
is ok? There is no preferred way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
null
being returned when an error is more appropriate?