From edf0a36237e94fddd4f60855d891c1f0bcbbdbeb Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 29 Jan 2021 13:53:08 -0800 Subject: [PATCH 01/19] deps --- packages/image_picker/image_picker/analysis_options.yaml | 5 +++++ packages/image_picker/image_picker/pubspec.yaml | 3 ++- .../image_picker_platform_interface/analysis_options.yaml | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 packages/image_picker/image_picker/analysis_options.yaml create mode 100644 packages/image_picker/image_picker_platform_interface/analysis_options.yaml diff --git a/packages/image_picker/image_picker/analysis_options.yaml b/packages/image_picker/image_picker/analysis_options.yaml new file mode 100644 index 000000000000..9b93fed4c35d --- /dev/null +++ b/packages/image_picker/image_picker/analysis_options.yaml @@ -0,0 +1,5 @@ +include: ../../../analysis_options.yaml + +analyzer: + enable-experiment: + - non-nullable diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index 075c90627bf4..21cd9390c465 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -17,7 +17,8 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^1.0.2 - image_picker_platform_interface: ^1.1.0 + image_picker_platform_interface: + path: ../image_picker_platform_interface dev_dependencies: video_player: ^0.10.3 diff --git a/packages/image_picker/image_picker_platform_interface/analysis_options.yaml b/packages/image_picker/image_picker_platform_interface/analysis_options.yaml new file mode 100644 index 000000000000..aafa40218310 --- /dev/null +++ b/packages/image_picker/image_picker_platform_interface/analysis_options.yaml @@ -0,0 +1,5 @@ +include: ../../../analysis_options.yaml + +analyzer: + enable-experiment: + - non-nullable \ No newline at end of file From 41212fc3a3544a22a20c0b5d04d025d51c20247f Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 29 Jan 2021 14:14:57 -0800 Subject: [PATCH 02/19] upstream dep for now --- packages/image_picker/image_picker/pubspec.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index 21cd9390c465..789ca13d5bcb 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -2,7 +2,7 @@ name: image_picker description: Flutter plugin for selecting images from the Android and iOS image library, and taking new pictures with the camera. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker -version: 0.6.7+22 +version: 0.6.7+21 flutter: plugin: @@ -17,8 +17,7 @@ dependencies: flutter: sdk: flutter flutter_plugin_android_lifecycle: ^1.0.2 - image_picker_platform_interface: - path: ../image_picker_platform_interface + image_picker_platform_interface: ^1.1.0 dev_dependencies: video_player: ^0.10.3 From fb198c952e2eb415fd4aa2898ef0932920f12ea4 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 11:44:45 -0800 Subject: [PATCH 03/19] draft --- .../method_channel_image_picker.dart | 11 ++++++----- .../image_picker_platform_interface/pubspec.yaml | 14 +++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 71704b63ced4..05205ecb66db 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; +import 'package:image_picker_platform_interface/src/types/lost_data.dart'; import 'package:meta/meta.dart' show required, visibleForTesting; import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; @@ -20,7 +21,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { MethodChannel get channel => _channel; @override - Future pickImage({ + Future pickImage({ @required ImageSource source, double maxWidth, double maxHeight, @@ -34,7 +35,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { imageQuality: imageQuality, preferredCameraDevice: preferredCameraDevice, ); - return path != null ? PickedFile(path) : null; + return path != null ? XFile(path) : null; } @override @@ -72,7 +73,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { } @override - Future pickVideo({ + Future pickVideo({ @required ImageSource source, CameraDevice preferredCameraDevice = CameraDevice.rear, Duration maxDuration, @@ -82,7 +83,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { maxDuration: maxDuration, preferredCameraDevice: preferredCameraDevice, ); - return path != null ? PickedFile(path) : null; + return path != null ? XFile(path) : null; } @override @@ -132,7 +133,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { final String path = result['path']; return LostData( - file: path != null ? PickedFile(path) : null, + file: path != null ? XFile(path) : null, exception: exception, type: retrieveType, ); diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml index b9ad12a50eb6..821114f2af92 100644 --- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml +++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml @@ -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.1 dev_dependencies: flutter_test: sdk: flutter - mockito: ^4.1.1 - pedantic: ^1.8.0+1 + mockito: ^5.0.0-nullsafety.5 + pedantic: ^1.10.0-nullsafety.3 environment: - sdk: ">=2.5.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" flutter: ">=1.10.0" From 21dd55ff930dadd518aaee58f82096c5140bf47b Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 12:12:27 -0800 Subject: [PATCH 04/19] platform_interface migrate to nnbd --- .../method_channel_image_picker.dart | 65 +++++++++---------- .../image_picker_platform.dart | 32 ++++----- .../lib/src/types/lost_data_response.dart | 6 +- .../lib/src/types/picked_file/base.dart | 2 +- .../lib/src/types/picked_file/html.dart | 8 +-- .../lib/src/types/picked_file/io.dart | 2 +- .../lib/src/types/picked_file/lost_data.dart | 6 +- .../pubspec.yaml | 2 +- .../method_channel_image_picker_test.dart | 6 +- .../new_method_channel_image_picker_test.dart | 6 +- .../test/picked_file_html_test.dart | 3 +- 11 files changed, 67 insertions(+), 71 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 05205ecb66db..f046d869a5ac 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -7,7 +7,6 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; -import 'package:image_picker_platform_interface/src/types/lost_data.dart'; import 'package:meta/meta.dart' show required, visibleForTesting; import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; @@ -21,32 +20,31 @@ class MethodChannelImagePicker extends ImagePickerPlatform { MethodChannel get channel => _channel; @override - Future pickImage({ - @required ImageSource source, - double maxWidth, - double maxHeight, - int imageQuality, + Future pickImage({ + 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, imageQuality: imageQuality, preferredCameraDevice: preferredCameraDevice, ); - return path != null ? XFile(path) : null; + return path != null ? PickedFile(path) : null; } @override - Future pickImagePath({ - @required ImageSource source, - double maxWidth, - double maxHeight, - int imageQuality, + Future 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'); @@ -73,26 +71,25 @@ class MethodChannelImagePicker extends ImagePickerPlatform { } @override - Future pickVideo({ - @required ImageSource source, + Future 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, ); - return path != null ? XFile(path) : null; + return path != null ? PickedFile(path) : null; } @override - Future pickVideoPath({ - @required ImageSource source, + Future pickVideoPath({ + required ImageSource source, CameraDevice preferredCameraDevice = CameraDevice.rear, - Duration maxDuration, + Duration? maxDuration, }) { - assert(source != null); return _channel.invokeMethod( 'pickVideo', { @@ -105,7 +102,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { @override Future retrieveLostData() async { - final Map result = + final Map? result = await _channel.invokeMapMethod('retrieve'); if (result == null) { @@ -114,26 +111,26 @@ 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 ? XFile(path) : null, + file: path != null ? PickedFile(path) : null, exception: exception, type: retrieveType, ); @@ -142,7 +139,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { @override // ignore: deprecated_member_use_from_same_package Future retrieveLostDataAsDartIoFile() async { - final Map result = + final Map? result = await _channel.invokeMapMethod('retrieve'); if (result == null) { // ignore: deprecated_member_use_from_same_package @@ -150,23 +147,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']; // ignore: deprecated_member_use_from_same_package return LostDataResponse( diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart index cbd604187714..48e6b7d2012e 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart @@ -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 pickImagePath({ - @required ImageSource source, - double maxWidth, - double maxHeight, - int imageQuality, + Future pickImagePath({ + 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 pickVideoPath({ - @required ImageSource source, + Future 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 pickImage({ - @required ImageSource source, - double maxWidth, - double maxHeight, - int imageQuality, + Future pickImage({ + 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 pickVideo({ - @required ImageSource source, + Future pickVideo({ + required ImageSource source, CameraDevice preferredCameraDevice = CameraDevice.rear, - Duration maxDuration, + Duration? maxDuration, }) { throw UnimplementedError('pickVideo() has not been implemented.'); } diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart index d82618b23cd1..557ef51e3b2c 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart @@ -34,7 +34,7 @@ class LostDataResponse { /// The file that was lost in a previous [pickImage] or [pickVideo] call due to MainActivity being destroyed. /// /// Can be null if [exception] exists. - final File file; + final File? file; /// The exception of the last [pickImage] or [pickVideo]. /// @@ -43,10 +43,10 @@ class LostDataResponse { /// 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; bool _empty = false; } diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/base.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/base.dart index 285294efcb3d..2b078ef28190 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/base.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/base.dart @@ -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 openRead([int start, int end]) { + Stream openRead([int? start, int? end]) { throw UnimplementedError('openRead() has not been implemented.'); } } diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart index ee5145009dc7..b855eb3fa20d 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart @@ -10,19 +10,19 @@ import './base.dart'; /// It wraps the bytes of a selected file. class PickedFile extends PickedFileBase { final String path; - final Uint8List _initBytes; + final Uint8List? _initBytes; /// Construct a PickedFile object from its ObjectUrl. /// /// Optionally, this can be initialized with `bytes` /// so no http requests are performed to retrieve files later. - PickedFile(this.path, {Uint8List bytes}) + PickedFile(this.path, {Uint8List? bytes}) : _initBytes = bytes, super(path); Future get _bytes async { if (_initBytes != null) { - return Future.value(UnmodifiableUint8ListView(_initBytes)); + return Future.value(UnmodifiableUint8ListView(_initBytes!)); } return http.readBytes(Uri.parse(path)); } @@ -38,7 +38,7 @@ class PickedFile extends PickedFileBase { } @override - Stream openRead([int start, int end]) async* { + Stream openRead([int? start, int? end]) async* { final bytes = await _bytes; yield bytes.sublist(start ?? 0, end ?? bytes.length); } diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/io.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/io.dart index dd64558bf044..4b56add0add4 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/io.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/io.dart @@ -29,7 +29,7 @@ class PickedFile extends PickedFileBase { } @override - Stream openRead([int start, int end]) { + Stream openRead([int? start, int? end]) { return _file .openRead(start ?? 0, end) .map((chunk) => Uint8List.fromList(chunk)); diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart index b94e69de219e..c1fd9ce8eb18 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart @@ -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; bool _empty = false; } diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml index 821114f2af92..4441643ceb93 100644 --- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml +++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml @@ -10,7 +10,7 @@ dependencies: sdk: flutter meta: ^1.3.0-nullsafety.6 http: ^0.13.0-nullsafety.0 - plugin_platform_interface: ^1.1.0-nullsafety.1 + plugin_platform_interface: ^1.1.0-nullsafety.2 dev_dependencies: flutter_test: diff --git a/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart index ddaad3d32f41..17fbb9afe69e 100644 --- a/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart @@ -303,7 +303,7 @@ void main() { final LostDataResponse response = await picker.retrieveLostDataAsDartIoFile(); expect(response.type, RetrieveType.image); - expect(response.file.path, '/example/path'); + expect(response.file?.path, '/example/path'); }); test('retrieveLostData get error response', () async { @@ -318,8 +318,8 @@ void main() { final LostDataResponse response = await picker.retrieveLostDataAsDartIoFile(); 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'); + expect(response.exception?.message, 'test_error_message'); }); test('retrieveLostData get null response', () async { diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index e7abe37e4838..126c171270ce 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -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'); }); 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'); + expect(response.exception?.message, 'test_error_message'); }); test('retrieveLostData get null response', () async { diff --git a/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart b/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart index 49d84ff88f88..ee0edbea03e0 100644 --- a/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/picked_file_html_test.dart @@ -6,13 +6,12 @@ import 'dart:convert'; import 'dart:html' as html; -import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; final String expectedStringContents = 'Hello, world!'; -final Uint8List bytes = utf8.encode(expectedStringContents); +final List bytes = utf8.encode(expectedStringContents); final html.File textFile = html.File([bytes], 'hello.txt'); final String textFileUrl = html.Url.createObjectUrl(textFile); From 29d8a8a057ef8d25cb67a0fa3cf77c085083b8ea Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 12:14:43 -0800 Subject: [PATCH 05/19] line eof --- .../image_picker_platform_interface/analysis_options.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/image_picker/image_picker_platform_interface/analysis_options.yaml b/packages/image_picker/image_picker_platform_interface/analysis_options.yaml index aafa40218310..9b93fed4c35d 100644 --- a/packages/image_picker/image_picker_platform_interface/analysis_options.yaml +++ b/packages/image_picker/image_picker_platform_interface/analysis_options.yaml @@ -2,4 +2,4 @@ include: ../../../analysis_options.yaml analyzer: enable-experiment: - - non-nullable \ No newline at end of file + - non-nullable From 906de01d52b15332bc5ad84e23e83660483f6bf5 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 12:18:09 -0800 Subject: [PATCH 06/19] changelog --- .../image_picker/image_picker_platform_interface/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index 581cf1830610..8ba9080de8ff 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.0-nullsafety + +* Migrate to NNBD. + ## 1.1.6 * Fix test asset file location. From 8f3745169255384e0729c5cac8a1c231efbfb30c Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 12:24:09 -0800 Subject: [PATCH 07/19] move image_picker to nnbd ignore list --- script/nnbd_plugins.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 44e5df9e95ef..4daa57556165 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -20,6 +20,7 @@ readonly NNBD_PLUGINS_LIST=( "url_launcher" "video_player" "webview_flutter" + "image_picker" ) # This list contains the list of plugins that have *not* been From 1161e1fa7da1beb157642aeeea2bac8f70fdc55f Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 12:28:15 -0800 Subject: [PATCH 08/19] revert changes in image_picker --- packages/image_picker/image_picker/analysis_options.yaml | 5 ----- packages/image_picker/image_picker/pubspec.yaml | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 packages/image_picker/image_picker/analysis_options.yaml diff --git a/packages/image_picker/image_picker/analysis_options.yaml b/packages/image_picker/image_picker/analysis_options.yaml deleted file mode 100644 index 9b93fed4c35d..000000000000 --- a/packages/image_picker/image_picker/analysis_options.yaml +++ /dev/null @@ -1,5 +0,0 @@ -include: ../../../analysis_options.yaml - -analyzer: - enable-experiment: - - non-nullable diff --git a/packages/image_picker/image_picker/pubspec.yaml b/packages/image_picker/image_picker/pubspec.yaml index 789ca13d5bcb..075c90627bf4 100755 --- a/packages/image_picker/image_picker/pubspec.yaml +++ b/packages/image_picker/image_picker/pubspec.yaml @@ -2,7 +2,7 @@ name: image_picker description: Flutter plugin for selecting images from the Android and iOS image library, and taking new pictures with the camera. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker -version: 0.6.7+21 +version: 0.6.7+22 flutter: plugin: From a9dbc006687e7596da543d2af3029729059a0248 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 14:47:43 -0800 Subject: [PATCH 09/19] skip platform_interface --- .../lib/src/method_channel/method_channel_image_picker.dart | 2 +- script/nnbd_plugins.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index f046d869a5ac..2956a2ee9060 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -7,7 +7,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; -import 'package:meta/meta.dart' show required, visibleForTesting; +import 'package:meta/meta.dart' show visibleForTesting; import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 4daa57556165..6eeffdfb7d1d 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -20,7 +20,7 @@ readonly NNBD_PLUGINS_LIST=( "url_launcher" "video_player" "webview_flutter" - "image_picker" + "image_picker_platform_interface" ) # This list contains the list of plugins that have *not* been From 66bde58ab430fcfb64d668ae06f75ccfa2972231 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 15:25:55 -0800 Subject: [PATCH 10/19] review --- .../image_picker_platform_interface/CHANGELOG.md | 2 +- .../image_picker_platform_interface/analysis_options.yaml | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 packages/image_picker/image_picker_platform_interface/analysis_options.yaml diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index 8ba9080de8ff..52c743396d03 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.0.0-nullsafety -* Migrate to NNBD. +* Migrate to null safety. ## 1.1.6 diff --git a/packages/image_picker/image_picker_platform_interface/analysis_options.yaml b/packages/image_picker/image_picker_platform_interface/analysis_options.yaml deleted file mode 100644 index 9b93fed4c35d..000000000000 --- a/packages/image_picker/image_picker_platform_interface/analysis_options.yaml +++ /dev/null @@ -1,5 +0,0 @@ -include: ../../../analysis_options.yaml - -analyzer: - enable-experiment: - - non-nullable From aa828fb4a98077a7dbfdf09660c1dcfcc66f8e3d Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 15:51:19 -0800 Subject: [PATCH 11/19] remove deprecated methods --- .../method_channel_image_picker.dart | 46 +-- .../image_picker_platform.dart | 74 ---- .../method_channel_image_picker_test.dart | 106 +++--- .../new_method_channel_image_picker_test.dart | 353 ------------------ 4 files changed, 61 insertions(+), 518 deletions(-) delete mode 100644 packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 2956a2ee9060..1c7f1045ac54 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -27,7 +27,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { int? imageQuality, CameraDevice preferredCameraDevice = CameraDevice.rear, }) async { - String? path = await pickImagePath( + String? path = await _pickImagePath( source: source, maxWidth: maxWidth, maxHeight: maxHeight, @@ -37,8 +37,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { return path != null ? PickedFile(path) : null; } - @override - Future pickImagePath({ + Future _pickImagePath({ required ImageSource source, double? maxWidth, double? maxHeight, @@ -76,7 +75,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { CameraDevice preferredCameraDevice = CameraDevice.rear, Duration? maxDuration, }) async { - String? path = await pickVideoPath( + String? path = await _pickVideoPath( source: source, maxDuration: maxDuration, preferredCameraDevice: preferredCameraDevice, @@ -84,8 +83,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform { return path != null ? PickedFile(path) : null; } - @override - Future pickVideoPath({ + Future _pickVideoPath({ required ImageSource source, CameraDevice preferredCameraDevice = CameraDevice.rear, Duration? maxDuration, @@ -135,40 +133,4 @@ class MethodChannelImagePicker extends ImagePickerPlatform { type: retrieveType, ); } - - @override - // ignore: deprecated_member_use_from_same_package - Future retrieveLostDataAsDartIoFile() async { - final Map? result = - await _channel.invokeMapMethod('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']; - assert(type == kTypeImage || type == kTypeVideo); - - RetrieveType? retrieveType; - if (type == kTypeImage) { - retrieveType = RetrieveType.image; - } else if (type == kTypeVideo) { - retrieveType = RetrieveType.video; - } - - PlatformException? exception; - if (result.containsKey('errorCode')) { - exception = PlatformException( - code: result['errorCode'], message: result['errorMessage']); - } - - final String? path = result['path']; - - // ignore: deprecated_member_use_from_same_package - return LostDataResponse( - file: path == null ? null : File(path), - exception: exception, - type: retrieveType); - } } diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart index 48e6b7d2012e..18753566d48d 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart @@ -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 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 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 retrieveLostDataAsDartIoFile() { - throw UnimplementedError( - 'retrieveLostDataAsDartIoFile() has not been implemented.'); - } - // Next version of the API. /// Returns a [PickedFile] with the image that was picked. diff --git a/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart index 17fbb9afe69e..126c171270ce 100644 --- a/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart @@ -25,10 +25,10 @@ void main() { log.clear(); }); - group('#pickImagePath', () { + group('#pickImage', () { test('passes the image source argument correctly', () async { - await picker.pickImagePath(source: ImageSource.camera); - await picker.pickImagePath(source: ImageSource.gallery); + await picker.pickImage(source: ImageSource.camera); + await picker.pickImage(source: ImageSource.gallery); expect( log, @@ -52,29 +52,36 @@ void main() { }); test('passes the width and height arguments correctly', () async { - await picker.pickImagePath(source: ImageSource.camera); - await picker.pickImagePath( + await picker.pickImage(source: ImageSource.camera); + await picker.pickImage( source: ImageSource.camera, maxWidth: 10.0, ); - await picker.pickImagePath( + await picker.pickImage( source: ImageSource.camera, maxHeight: 10.0, ); - await picker.pickImagePath( + await picker.pickImage( source: ImageSource.camera, maxWidth: 10.0, maxHeight: 20.0, ); - await picker.pickImagePath( - source: ImageSource.camera, maxWidth: 10.0, imageQuality: 70); - await picker.pickImagePath( - source: ImageSource.camera, maxHeight: 10.0, imageQuality: 70); - await picker.pickImagePath( - source: ImageSource.camera, - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70); + await picker.pickImage( + source: ImageSource.camera, + maxWidth: 10.0, + imageQuality: 70, + ); + await picker.pickImage( + source: ImageSource.camera, + maxHeight: 10.0, + imageQuality: 70, + ); + await picker.pickImage( + source: ImageSource.camera, + maxWidth: 10.0, + maxHeight: 20.0, + imageQuality: 70, + ); expect( log, @@ -134,14 +141,12 @@ void main() { test('does not accept a negative width or height argument', () { expect( - () => - picker.pickImagePath(source: ImageSource.camera, maxWidth: -1.0), + () => picker.pickImage(source: ImageSource.camera, maxWidth: -1.0), throwsArgumentError, ); expect( - () => - picker.pickImagePath(source: ImageSource.camera, maxHeight: -1.0), + () => picker.pickImage(source: ImageSource.camera, maxHeight: -1.0), throwsArgumentError, ); }); @@ -150,12 +155,12 @@ void main() { picker.channel .setMockMethodCallHandler((MethodCall methodCall) => null); - expect(await picker.pickImagePath(source: ImageSource.gallery), isNull); - expect(await picker.pickImagePath(source: ImageSource.camera), isNull); + expect(await picker.pickImage(source: ImageSource.gallery), isNull); + expect(await picker.pickImage(source: ImageSource.camera), isNull); }); test('camera position defaults to back', () async { - await picker.pickImagePath(source: ImageSource.camera); + await picker.pickImage(source: ImageSource.camera); expect( log, @@ -172,7 +177,7 @@ void main() { }); test('camera position can set to front', () async { - await picker.pickImagePath( + await picker.pickImage( source: ImageSource.camera, preferredCameraDevice: CameraDevice.front); @@ -193,8 +198,8 @@ void main() { group('#pickVideoPath', () { test('passes the image source argument correctly', () async { - await picker.pickVideoPath(source: ImageSource.camera); - await picker.pickVideoPath(source: ImageSource.gallery); + await picker.pickVideo(source: ImageSource.camera); + await picker.pickVideo(source: ImageSource.gallery); expect( log, @@ -214,15 +219,19 @@ void main() { }); test('passes the duration argument correctly', () async { - await picker.pickVideoPath(source: ImageSource.camera); - await picker.pickVideoPath( - source: ImageSource.camera, - maxDuration: const Duration(seconds: 10)); - await picker.pickVideoPath( - source: ImageSource.camera, - maxDuration: const Duration(minutes: 1)); - await picker.pickVideoPath( - source: ImageSource.camera, maxDuration: const Duration(hours: 1)); + await picker.pickVideo(source: ImageSource.camera); + await picker.pickVideo( + source: ImageSource.camera, + maxDuration: const Duration(seconds: 10), + ); + await picker.pickVideo( + source: ImageSource.camera, + maxDuration: const Duration(minutes: 1), + ); + await picker.pickVideo( + source: ImageSource.camera, + maxDuration: const Duration(hours: 1), + ); expect( log, [ @@ -254,12 +263,12 @@ void main() { picker.channel .setMockMethodCallHandler((MethodCall methodCall) => null); - expect(await picker.pickVideoPath(source: ImageSource.gallery), isNull); - expect(await picker.pickVideoPath(source: ImageSource.camera), isNull); + expect(await picker.pickVideo(source: ImageSource.gallery), isNull); + expect(await picker.pickVideo(source: ImageSource.camera), isNull); }); test('camera position defaults to back', () async { - await picker.pickVideoPath(source: ImageSource.camera); + await picker.pickVideo(source: ImageSource.camera); expect( log, @@ -274,9 +283,10 @@ void main() { }); test('camera position can set to front', () async { - await picker.pickVideoPath( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); + await picker.pickVideo( + source: ImageSource.camera, + preferredCameraDevice: CameraDevice.front, + ); expect( log, @@ -291,7 +301,7 @@ void main() { }); }); - group('#retrieveLostDataAsDartIoFile', () { + group('#retrieveLostData', () { test('retrieveLostData get success response', () async { picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { return { @@ -300,8 +310,7 @@ void main() { }; }); // ignore: deprecated_member_use_from_same_package - final LostDataResponse response = - await picker.retrieveLostDataAsDartIoFile(); + final LostData response = await picker.retrieveLostData(); expect(response.type, RetrieveType.image); expect(response.file?.path, '/example/path'); }); @@ -315,8 +324,7 @@ void main() { }; }); // ignore: deprecated_member_use_from_same_package - final LostDataResponse response = - await picker.retrieveLostDataAsDartIoFile(); + 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'); @@ -326,7 +334,7 @@ void main() { picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { return null; }); - expect((await picker.retrieveLostDataAsDartIoFile()).isEmpty, true); + expect((await picker.retrieveLostData()).isEmpty, true); }); test('retrieveLostData get both path and error should throw', () async { @@ -338,8 +346,8 @@ void main() { 'path': '/example/path', }; }); - expect(picker.retrieveLostDataAsDartIoFile(), throwsAssertionError); + expect(picker.retrieveLostData(), throwsAssertionError); }); - }, skip: isBrowser); + }); }); } diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart deleted file mode 100644 index 126c171270ce..000000000000 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright 2019 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; -import 'package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart'; - -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('$MethodChannelImagePicker', () { - MethodChannelImagePicker picker = MethodChannelImagePicker(); - - final List log = []; - - setUp(() { - picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - return ''; - }); - - log.clear(); - }); - - group('#pickImage', () { - test('passes the image source argument correctly', () async { - await picker.pickImage(source: ImageSource.camera); - await picker.pickImage(source: ImageSource.gallery); - - expect( - log, - [ - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': 0 - }), - isMethodCall('pickImage', arguments: { - 'source': 1, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': 0 - }), - ], - ); - }); - - test('passes the width and height arguments correctly', () async { - await picker.pickImage(source: ImageSource.camera); - await picker.pickImage( - source: ImageSource.camera, - maxWidth: 10.0, - ); - await picker.pickImage( - source: ImageSource.camera, - maxHeight: 10.0, - ); - await picker.pickImage( - source: ImageSource.camera, - maxWidth: 10.0, - maxHeight: 20.0, - ); - await picker.pickImage( - source: ImageSource.camera, - maxWidth: 10.0, - imageQuality: 70, - ); - await picker.pickImage( - source: ImageSource.camera, - maxHeight: 10.0, - imageQuality: 70, - ); - await picker.pickImage( - source: ImageSource.camera, - maxWidth: 10.0, - maxHeight: 20.0, - imageQuality: 70, - ); - - expect( - log, - [ - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': 0 - }), - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': 0 - }), - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': null, - 'cameraDevice': 0 - }), - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': null, - 'cameraDevice': 0 - }), - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': 10.0, - 'maxHeight': null, - 'imageQuality': 70, - 'cameraDevice': 0 - }), - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': null, - 'maxHeight': 10.0, - 'imageQuality': 70, - 'cameraDevice': 0 - }), - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': 10.0, - 'maxHeight': 20.0, - 'imageQuality': 70, - 'cameraDevice': 0 - }), - ], - ); - }); - - test('does not accept a negative width or height argument', () { - expect( - () => picker.pickImage(source: ImageSource.camera, maxWidth: -1.0), - throwsArgumentError, - ); - - expect( - () => picker.pickImage(source: ImageSource.camera, maxHeight: -1.0), - throwsArgumentError, - ); - }); - - test('handles a null image path response gracefully', () async { - picker.channel - .setMockMethodCallHandler((MethodCall methodCall) => null); - - expect(await picker.pickImage(source: ImageSource.gallery), isNull); - expect(await picker.pickImage(source: ImageSource.camera), isNull); - }); - - test('camera position defaults to back', () async { - await picker.pickImage(source: ImageSource.camera); - - expect( - log, - [ - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': 0, - }), - ], - ); - }); - - test('camera position can set to front', () async { - await picker.pickImage( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front); - - expect( - log, - [ - isMethodCall('pickImage', arguments: { - 'source': 0, - 'maxWidth': null, - 'maxHeight': null, - 'imageQuality': null, - 'cameraDevice': 1, - }), - ], - ); - }); - }); - - group('#pickVideoPath', () { - test('passes the image source argument correctly', () async { - await picker.pickVideo(source: ImageSource.camera); - await picker.pickVideo(source: ImageSource.gallery); - - expect( - log, - [ - isMethodCall('pickVideo', arguments: { - 'source': 0, - 'cameraDevice': 0, - 'maxDuration': null, - }), - isMethodCall('pickVideo', arguments: { - 'source': 1, - 'cameraDevice': 0, - 'maxDuration': null, - }), - ], - ); - }); - - test('passes the duration argument correctly', () async { - await picker.pickVideo(source: ImageSource.camera); - await picker.pickVideo( - source: ImageSource.camera, - maxDuration: const Duration(seconds: 10), - ); - await picker.pickVideo( - source: ImageSource.camera, - maxDuration: const Duration(minutes: 1), - ); - await picker.pickVideo( - source: ImageSource.camera, - maxDuration: const Duration(hours: 1), - ); - expect( - log, - [ - isMethodCall('pickVideo', arguments: { - 'source': 0, - 'maxDuration': null, - 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { - 'source': 0, - 'maxDuration': 10, - 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { - 'source': 0, - 'maxDuration': 60, - 'cameraDevice': 0, - }), - isMethodCall('pickVideo', arguments: { - 'source': 0, - 'maxDuration': 3600, - 'cameraDevice': 0, - }), - ], - ); - }); - - test('handles a null video path response gracefully', () async { - picker.channel - .setMockMethodCallHandler((MethodCall methodCall) => null); - - expect(await picker.pickVideo(source: ImageSource.gallery), isNull); - expect(await picker.pickVideo(source: ImageSource.camera), isNull); - }); - - test('camera position defaults to back', () async { - await picker.pickVideo(source: ImageSource.camera); - - expect( - log, - [ - isMethodCall('pickVideo', arguments: { - 'source': 0, - 'cameraDevice': 0, - 'maxDuration': null, - }), - ], - ); - }); - - test('camera position can set to front', () async { - await picker.pickVideo( - source: ImageSource.camera, - preferredCameraDevice: CameraDevice.front, - ); - - expect( - log, - [ - isMethodCall('pickVideo', arguments: { - 'source': 0, - 'maxDuration': null, - 'cameraDevice': 1, - }), - ], - ); - }); - }); - - group('#retrieveLostData', () { - test('retrieveLostData get success response', () async { - picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { - return { - 'type': 'image', - 'path': '/example/path', - }; - }); - // ignore: deprecated_member_use_from_same_package - final LostData response = await picker.retrieveLostData(); - expect(response.type, RetrieveType.image); - expect(response.file?.path, '/example/path'); - }); - - test('retrieveLostData get error response', () async { - picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { - return { - 'type': 'video', - 'errorCode': 'test_error_code', - 'errorMessage': 'test_error_message', - }; - }); - // 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'); - }); - - test('retrieveLostData get null response', () async { - picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { - return null; - }); - expect((await picker.retrieveLostData()).isEmpty, true); - }); - - test('retrieveLostData get both path and error should throw', () async { - picker.channel.setMockMethodCallHandler((MethodCall methodCall) async { - return { - 'type': 'video', - 'errorCode': 'test_error_code', - 'errorMessage': 'test_error_message', - 'path': '/example/path', - }; - }); - expect(picker.retrieveLostData(), throwsAssertionError); - }); - }); - }); -} From fcf55a10b2e49f83abcf0f3a036242ddeb212019 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 15:52:24 -0800 Subject: [PATCH 12/19] revert test name for easier review --- ...picker_test.dart => new_method_channel_image_picker_test.dart} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/image_picker/image_picker_platform_interface/test/{method_channel_image_picker_test.dart => new_method_channel_image_picker_test.dart} (100%) diff --git a/packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart similarity index 100% rename from packages/image_picker/image_picker_platform_interface/test/method_channel_image_picker_test.dart rename to packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart From be2a278b94abbe2e9a912b6add87b40757a65f66 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Mon, 1 Feb 2021 19:43:34 -0800 Subject: [PATCH 13/19] review --- .../lib/src/platform_interface/image_picker_platform.dart | 4 ++++ .../lib/src/types/picked_file/lost_data.dart | 2 ++ 2 files changed, 6 insertions(+) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart index 18753566d48d..aad0e4ebb1c9 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart @@ -67,6 +67,8 @@ 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. + /// + /// If no images were picked, the return value is null. Future pickImage({ required ImageSource source, double? maxWidth, @@ -91,6 +93,8 @@ 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. + /// + /// If no images were picked, the return value is null. Future pickVideo({ required ImageSource source, CameraDevice preferredCameraDevice = CameraDevice.rear, diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart index c1fd9ce8eb18..831c7bd6cb15 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/lost_data.dart @@ -43,6 +43,8 @@ class LostData { final PlatformException? exception; /// Can either be [RetrieveType.image] or [RetrieveType.video]; + /// + /// If the lost data is empty, this will be null. final RetrieveType? type; bool _empty = false; From b5487923edbd744dfbd46c651ca15226ad854b43 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 2 Feb 2021 10:20:44 -0800 Subject: [PATCH 14/19] add breaking changes in changelogs --- .../image_picker/image_picker_platform_interface/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index 52c743396d03..e0139339592a 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -1,6 +1,8 @@ ## 2.0.0-nullsafety * Migrate to null safety. +* Breaking Changes: + * Removed the deprecated methods: `ImagePickerPlatform.retrieveLostDataAsDartIoFile`,`ImagePickerPlatform.pickImagePath` and `ImagePickerPlatform.pickVideoPath`. ## 1.1.6 From afb8614d68311d9c39ee9d9725d036c669113a00 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 3 Feb 2021 14:13:21 -0800 Subject: [PATCH 15/19] review --- .../test/new_method_channel_image_picker_test.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart index 126c171270ce..df35f8fd96b8 100644 --- a/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart +++ b/packages/image_picker/image_picker_platform_interface/test/new_method_channel_image_picker_test.dart @@ -312,7 +312,8 @@ 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, isNotNull); + expect(response.file!.path, '/example/path'); }); test('retrieveLostData get error response', () async { @@ -326,8 +327,9 @@ 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, isNotNull); + expect(response.exception!.code, 'test_error_code'); + expect(response.exception!.message, 'test_error_message'); }); test('retrieveLostData get null response', () async { From 4c32c3d43413d93bdac7c7145ee5ee93753c6dc7 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 3 Feb 2021 14:33:45 -0800 Subject: [PATCH 16/19] review --- .../CHANGELOG.md | 1 + .../lib/src/types/lost_data_response.dart | 52 ------------------- .../lib/src/types/types.dart | 1 - 3 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart diff --git a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md index e0139339592a..fc953e4e6333 100644 --- a/packages/image_picker/image_picker_platform_interface/CHANGELOG.md +++ b/packages/image_picker/image_picker_platform_interface/CHANGELOG.md @@ -3,6 +3,7 @@ * Migrate to null safety. * Breaking Changes: * Removed the deprecated methods: `ImagePickerPlatform.retrieveLostDataAsDartIoFile`,`ImagePickerPlatform.pickImagePath` and `ImagePickerPlatform.pickVideoPath`. + * Removed deprecated class: `LostDataResponse`. ## 1.1.6 diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart deleted file mode 100644 index 557ef51e3b2c..000000000000 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/lost_data_response.dart +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:io'; - -import 'package:flutter/services.dart'; -import 'package:image_picker_platform_interface/src/types/types.dart'; - -/// The response object of [ImagePicker.retrieveLostData]. -/// -/// Only applies to Android. -/// See also: -/// * [ImagePicker.retrieveLostData] for more details on retrieving lost data. -@Deprecated('Use methods that return a LostData object instead.') -class LostDataResponse { - /// Creates an instance with the given [file], [exception], and [type]. Any of - /// the params may be null, but this is never considered to be empty. - LostDataResponse({this.file, this.exception, this.type}); - - /// Initializes an instance with all member params set to null and considered - /// to be empty. - LostDataResponse.empty() - : file = null, - exception = null, - type = null, - _empty = true; - - /// Whether it is an empty response. - /// - /// An empty response should have [file], [exception] and [type] to be null. - bool get isEmpty => _empty; - - /// The file that was lost in a previous [pickImage] or [pickVideo] call due to MainActivity being destroyed. - /// - /// Can be null if [exception] exists. - final File? file; - - /// The exception of the last [pickImage] or [pickVideo]. - /// - /// If the last [pickImage] or [pickVideo] threw some exception before the MainActivity destruction, this variable keeps that - /// exception. - /// 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; - - /// Can either be [RetrieveType.image] or [RetrieveType.video]; - final RetrieveType? type; - - bool _empty = false; -} diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/types/types.dart b/packages/image_picker/image_picker_platform_interface/lib/src/types/types.dart index 9c44fae1aa9d..f38a4ec74005 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/types/types.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/types/types.dart @@ -1,6 +1,5 @@ export 'camera_device.dart'; export 'image_source.dart'; -export 'lost_data_response.dart'; export 'retrieve_type.dart'; export 'picked_file/picked_file.dart'; From fd4595c32ca24abba694020950b35d6f5e4ba6dc Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 3 Feb 2021 15:15:11 -0800 Subject: [PATCH 17/19] review --- .../lib/src/method_channel/method_channel_image_picker.dart | 1 - .../lib/src/platform_interface/image_picker_platform.dart | 1 - .../image_picker/image_picker_platform_interface/pubspec.yaml | 1 - 3 files changed, 3 deletions(-) diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart index 1c7f1045ac54..8535f9dfb20e 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; diff --git a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart index aad0e4ebb1c9..44b85f17f3db 100644 --- a/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart +++ b/packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart @@ -4,7 +4,6 @@ import 'dart:async'; -import 'package:meta/meta.dart' show required; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart'; diff --git a/packages/image_picker/image_picker_platform_interface/pubspec.yaml b/packages/image_picker/image_picker_platform_interface/pubspec.yaml index 4441643ceb93..d5f5ce93016b 100644 --- a/packages/image_picker/image_picker_platform_interface/pubspec.yaml +++ b/packages/image_picker/image_picker_platform_interface/pubspec.yaml @@ -15,7 +15,6 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - mockito: ^5.0.0-nullsafety.5 pedantic: ^1.10.0-nullsafety.3 environment: From beca9621749ce2e1cfedeae963468e58f6faa4c3 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 3 Feb 2021 15:17:41 -0800 Subject: [PATCH 18/19] exclude image picker on stable --- script/nnbd_plugins.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index 834ce9f2e1ac..f1cc16167d7f 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -21,6 +21,7 @@ readonly NNBD_PLUGINS_LIST=( "url_launcher" "video_player" "webview_flutter" + "image_picker" "image_picker_platform_interface" ) From 9bb91018312fd618b4220d8814a68778f98927f7 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Thu, 4 Feb 2021 10:55:19 -0800 Subject: [PATCH 19/19] exclude image picker in build all plugins because http dep conflicts --- script/build_all_plugins_app.sh | 1 + script/nnbd_plugins.sh | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/script/build_all_plugins_app.sh b/script/build_all_plugins_app.sh index 9d9e38550ed5..7807e6a98bce 100755 --- a/script/build_all_plugins_app.sh +++ b/script/build_all_plugins_app.sh @@ -30,6 +30,7 @@ readonly EXCLUDED_PLUGINS_LIST=( "google_sign_in_platform_interface" "google_sign_in_web" "image_picker_platform_interface" + "image_picker" "instrumentation_adapter" "local_auth" # flutter_plugin_android_lifecycle conflict "path_provider_linux" diff --git a/script/nnbd_plugins.sh b/script/nnbd_plugins.sh index f1cc16167d7f..b43d11c2fe1d 100644 --- a/script/nnbd_plugins.sh +++ b/script/nnbd_plugins.sh @@ -22,7 +22,6 @@ readonly NNBD_PLUGINS_LIST=( "video_player" "webview_flutter" "image_picker" - "image_picker_platform_interface" ) # This list contains the list of plugins that have *not* been