Thanks to visit codestin.com
Credit goes to github.com

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

[image_picker] Update platform interface analysis options #4837

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.4.4

* Internal code cleanup for stricter analysis options.

## 2.4.3

* Removes dependency on `meta`.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export 'package:cross_file/cross_file.dart';
export 'package:image_picker_platform_interface/src/platform_interface/image_picker_platform.dart';
export 'package:image_picker_platform_interface/src/types/types.dart';
export 'package:cross_file/cross_file.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flutter/services.dart';

import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';

final MethodChannel _channel = MethodChannel('plugins.flutter.io/image_picker');
const MethodChannel _channel = MethodChannel('plugins.flutter.io/image_picker');

/// An implementation of [ImagePickerPlatform] that uses method channels.
class MethodChannelImagePicker extends ImagePickerPlatform {
Expand All @@ -25,7 +25,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
int? imageQuality,
CameraDevice preferredCameraDevice = CameraDevice.rear,
}) async {
String? path = await _getImagePath(
final String? path = await _getImagePath(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
Expand All @@ -46,9 +46,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
maxHeight: maxHeight,
imageQuality: imageQuality,
);
if (paths == null) return null;
if (paths == null) {
return null;
}

return paths.map((path) => PickedFile(path)).toList();
return paths.map((dynamic path) => PickedFile(path as String)).toList();
}

Future<List<dynamic>?> _getMultiImagePath({
Expand Down Expand Up @@ -151,7 +153,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {

assert(result.containsKey('path') != result.containsKey('errorCode'));

final String? type = result['type'];
final String? type = result['type'] as String?;
assert(type == kTypeImage || type == kTypeVideo);

RetrieveType? retrieveType;
Expand All @@ -164,10 +166,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
PlatformException? exception;
if (result.containsKey('errorCode')) {
exception = PlatformException(
code: result['errorCode'], message: result['errorMessage']);
code: result['errorCode']! as String,
message: result['errorMessage'] as String?);
}

final String? path = result['path'];
final String? path = result['path'] as String?;

return LostData(
file: path != null ? PickedFile(path) : null,
Expand All @@ -184,7 +187,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
int? imageQuality,
CameraDevice preferredCameraDevice = CameraDevice.rear,
}) async {
String? path = await _getImagePath(
final String? path = await _getImagePath(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
Expand All @@ -205,9 +208,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
maxHeight: maxHeight,
imageQuality: imageQuality,
);
if (paths == null) return null;
if (paths == null) {
return null;
}

return paths.map((path) => XFile(path)).toList();
return paths.map((dynamic path) => XFile(path as String)).toList();
}

@override
Expand All @@ -228,7 +233,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
Future<LostDataResponse> getLostData() async {
List<XFile>? pickedFileList;

Map<String, dynamic>? result =
final Map<String, dynamic>? result =
await _channel.invokeMapMethod<String, dynamic>('retrieve');

if (result == null) {
Expand All @@ -237,7 +242,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {

assert(result.containsKey('path') != result.containsKey('errorCode'));

final String? type = result['type'];
final String? type = result['type'] as String?;
assert(type == kTypeImage || type == kTypeVideo);

RetrieveType? retrieveType;
Expand All @@ -250,15 +255,17 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
PlatformException? exception;
if (result.containsKey('errorCode')) {
exception = PlatformException(
code: result['errorCode'], message: result['errorMessage']);
code: result['errorCode']! as String,
message: result['errorMessage'] as String?);
}

final String? path = result['path'];
final String? path = result['path'] as String?;

final pathList = result['pathList'];
final List<String>? pathList =
(result['pathList'] as List<dynamic>?)?.cast<String>();
if (pathList != null) {
pickedFileList = [];
for (String path in pathList) {
pickedFileList = <XFile>[];
for (final String path in pathList) {
pickedFileList.add(XFile(path));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import 'dart:async';

import 'package:cross_file/cross_file.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart';
import 'package:image_picker_platform_interface/src/types/types.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

/// The interface that implementations of image_picker must implement.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import 'package:flutter/foundation.dart' show immutable;
@immutable
abstract class PickedFileBase {
/// Construct a PickedFile
PickedFileBase(String path);
// ignore: avoid_unused_constructor_parameters
const PickedFileBase(String path);

/// Get the path of the picked file.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ import './base.dart';
///
/// It wraps the bytes of a selected file.
class PickedFile extends PickedFileBase {
final String path;
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})
const PickedFile(this.path, {Uint8List? bytes})
: _initBytes = bytes,
super(path);

@override
final String path;
final Uint8List? _initBytes;

Future<Uint8List> get _bytes async {
if (_initBytes != null) {
return Future.value(UnmodifiableUint8ListView(_initBytes!));
return Future<Uint8List>.value(UnmodifiableUint8ListView(_initBytes!));
}
return http.readBytes(Uri.parse(path));
}
Expand All @@ -38,12 +39,12 @@ class PickedFile extends PickedFileBase {

@override
Future<Uint8List> readAsBytes() async {
return Future.value(await _bytes);
return Future<Uint8List>.value(await _bytes);
}

@override
Stream<Uint8List> openRead([int? start, int? end]) async* {
final bytes = await _bytes;
final Uint8List bytes = await _bytes;
yield bytes.sublist(start ?? 0, end ?? bytes.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import './base.dart';

/// A PickedFile backed by a dart:io File.
class PickedFile extends PickedFileBase {
final File _file;

/// Construct a PickedFile object backed by a dart:io File.
PickedFile(String path)
: _file = File(path),
super(path);

final File _file;

@override
String get path {
return _file.path;
Expand All @@ -36,6 +36,6 @@ class PickedFile extends PickedFileBase {
Stream<Uint8List> openRead([int? start, int? end]) {
return _file
.openRead(start ?? 0, end)
.map((chunk) => Uint8List.fromList(chunk));
.map((List<int> chunk) => Uint8List.fromList(chunk));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

export 'camera_device.dart';
export 'image_source.dart';
export 'retrieve_type.dart';
export 'picked_file/picked_file.dart';
export 'lost_data_response.dart';
export 'picked_file/picked_file.dart';
export 'retrieve_type.dart';

/// Denotes that an image is being picked.
const String kTypeImage = 'image';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/i
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
# 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: 2.4.3
version: 2.4.4

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"

dependencies:
cross_file: ^0.3.1+1
flutter:
sdk: flutter
http: ^0.13.0
plugin_platform_interface: ^2.1.0
cross_file: ^0.3.1+1

dev_dependencies:
flutter_test:
sdk: flutter
pedantic: ^1.10.0
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();

group('$MethodChannelImagePicker', () {
MethodChannelImagePicker picker = MethodChannelImagePicker();
final MethodChannelImagePicker picker = MethodChannelImagePicker();

final List<MethodCall> log = <MethodCall>[];
dynamic returnValue = '';
Expand Down Expand Up @@ -223,7 +223,7 @@ void main() {

group('#pickMultiImage', () {
test('calls the method correctly', () async {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
await picker.pickMultiImage();

expect(
Expand All @@ -239,7 +239,7 @@ void main() {
});

test('passes the width and height arguments correctly', () async {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
await picker.pickMultiImage();
await picker.pickMultiImage(
maxWidth: 10.0,
Expand Down Expand Up @@ -308,7 +308,7 @@ void main() {
});

test('does not accept a negative width or height argument', () {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
expect(
() => picker.pickMultiImage(maxWidth: -1.0),
throwsArgumentError,
Expand All @@ -321,7 +321,7 @@ void main() {
});

test('does not accept a invalid imageQuality argument', () {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
expect(
() => picker.pickMultiImage(imageQuality: -1),
throwsArgumentError,
Expand Down Expand Up @@ -691,7 +691,7 @@ void main() {

group('#getMultiImage', () {
test('calls the method correctly', () async {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
await picker.getMultiImage();

expect(
Expand All @@ -707,7 +707,7 @@ void main() {
});

test('passes the width and height arguments correctly', () async {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
await picker.getMultiImage();
await picker.getMultiImage(
maxWidth: 10.0,
Expand Down Expand Up @@ -776,7 +776,7 @@ void main() {
});

test('does not accept a negative width or height argument', () {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
expect(
() => picker.getMultiImage(maxWidth: -1.0),
throwsArgumentError,
Expand All @@ -789,7 +789,7 @@ void main() {
});

test('does not accept a invalid imageQuality argument', () {
returnValue = ['0', '1'];
returnValue = <dynamic>['0', '1'];
expect(
() => picker.getMultiImage(imageQuality: -1),
throwsArgumentError,
Expand Down Expand Up @@ -934,7 +934,7 @@ void main() {
return <String, dynamic>{
'type': 'image',
'path': '/example/path1',
'pathList': ['/example/path0', '/example/path1'],
'pathList': <dynamic>['/example/path0', '/example/path1'],
};
});
final LostDataResponse response = await picker.getLostData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import 'dart:html' as html;
import 'package:flutter_test/flutter_test.dart';
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';

final String expectedStringContents = 'Hello, world!';
const String expectedStringContents = 'Hello, world!';
final List<int> bytes = utf8.encode(expectedStringContents);
final html.File textFile = html.File([bytes], 'hello.txt');
final html.File textFile = html.File(<List<int>>[bytes], 'hello.txt');
final String textFileUrl = html.Url.createObjectUrl(textFile);

void main() {
group('Create with an objectUrl', () {
final pickedFile = PickedFile(textFileUrl);
final PickedFile pickedFile = PickedFile(textFileUrl);

test('Can be read as a string', () async {
expect(await pickedFile.readAsString(), equals(expectedStringContents));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';

final pathPrefix =
final String pathPrefix =
Directory.current.path.endsWith('test') ? './assets/' : './test/assets/';
final path = pathPrefix + 'hello.txt';
final String expectedStringContents = 'Hello, world!';
final String path = pathPrefix + 'hello.txt';
const String expectedStringContents = 'Hello, world!';
final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents));
final File textFile = File(path);
final String textFilePath = textFile.path;
Expand Down
1 change: 0 additions & 1 deletion script/configs/custom_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
- google_sign_in/google_sign_in
- google_sign_in/google_sign_in_platform_interface
- google_sign_in/google_sign_in_web
- image_picker/image_picker_platform_interface
- in_app_purchase/in_app_purchase
- in_app_purchase/in_app_purchase_android
- in_app_purchase/in_app_purchase_storekit
Expand Down