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

Commit 0a579fe

Browse files
[image_picker] Update platform interface analysis options (#4837)
1 parent 304b83d commit 0a579fe

14 files changed

Lines changed: 63 additions & 53 deletions

File tree

packages/image_picker/image_picker_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.4.4
2+
3+
* Internal code cleanup for stricter analysis options.
4+
15
## 2.4.3
26

37
* Removes dependency on `meta`.

packages/image_picker/image_picker_platform_interface/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/image_picker/image_picker_platform_interface/lib/image_picker_platform_interface.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
export 'package:cross_file/cross_file.dart';
56
export 'package:image_picker_platform_interface/src/platform_interface/image_picker_platform.dart';
67
export 'package:image_picker_platform_interface/src/types/types.dart';
7-
export 'package:cross_file/cross_file.dart';

packages/image_picker/image_picker_platform_interface/lib/src/method_channel/method_channel_image_picker.dart

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:flutter/services.dart';
99

1010
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
1111

12-
final MethodChannel _channel = MethodChannel('plugins.flutter.io/image_picker');
12+
const MethodChannel _channel = MethodChannel('plugins.flutter.io/image_picker');
1313

1414
/// An implementation of [ImagePickerPlatform] that uses method channels.
1515
class MethodChannelImagePicker extends ImagePickerPlatform {
@@ -25,7 +25,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
2525
int? imageQuality,
2626
CameraDevice preferredCameraDevice = CameraDevice.rear,
2727
}) async {
28-
String? path = await _getImagePath(
28+
final String? path = await _getImagePath(
2929
source: source,
3030
maxWidth: maxWidth,
3131
maxHeight: maxHeight,
@@ -46,9 +46,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
4646
maxHeight: maxHeight,
4747
imageQuality: imageQuality,
4848
);
49-
if (paths == null) return null;
49+
if (paths == null) {
50+
return null;
51+
}
5052

51-
return paths.map((path) => PickedFile(path)).toList();
53+
return paths.map((dynamic path) => PickedFile(path as String)).toList();
5254
}
5355

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

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

154-
final String? type = result['type'];
156+
final String? type = result['type'] as String?;
155157
assert(type == kTypeImage || type == kTypeVideo);
156158

157159
RetrieveType? retrieveType;
@@ -164,10 +166,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
164166
PlatformException? exception;
165167
if (result.containsKey('errorCode')) {
166168
exception = PlatformException(
167-
code: result['errorCode'], message: result['errorMessage']);
169+
code: result['errorCode']! as String,
170+
message: result['errorMessage'] as String?);
168171
}
169172

170-
final String? path = result['path'];
173+
final String? path = result['path'] as String?;
171174

172175
return LostData(
173176
file: path != null ? PickedFile(path) : null,
@@ -184,7 +187,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
184187
int? imageQuality,
185188
CameraDevice preferredCameraDevice = CameraDevice.rear,
186189
}) async {
187-
String? path = await _getImagePath(
190+
final String? path = await _getImagePath(
188191
source: source,
189192
maxWidth: maxWidth,
190193
maxHeight: maxHeight,
@@ -205,9 +208,11 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
205208
maxHeight: maxHeight,
206209
imageQuality: imageQuality,
207210
);
208-
if (paths == null) return null;
211+
if (paths == null) {
212+
return null;
213+
}
209214

210-
return paths.map((path) => XFile(path)).toList();
215+
return paths.map((dynamic path) => XFile(path as String)).toList();
211216
}
212217

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

231-
Map<String, dynamic>? result =
236+
final Map<String, dynamic>? result =
232237
await _channel.invokeMapMethod<String, dynamic>('retrieve');
233238

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

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

240-
final String? type = result['type'];
245+
final String? type = result['type'] as String?;
241246
assert(type == kTypeImage || type == kTypeVideo);
242247

243248
RetrieveType? retrieveType;
@@ -250,15 +255,17 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
250255
PlatformException? exception;
251256
if (result.containsKey('errorCode')) {
252257
exception = PlatformException(
253-
code: result['errorCode'], message: result['errorMessage']);
258+
code: result['errorCode']! as String,
259+
message: result['errorMessage'] as String?);
254260
}
255261

256-
final String? path = result['path'];
262+
final String? path = result['path'] as String?;
257263

258-
final pathList = result['pathList'];
264+
final List<String>? pathList =
265+
(result['pathList'] as List<dynamic>?)?.cast<String>();
259266
if (pathList != null) {
260-
pickedFileList = [];
261-
for (String path in pathList) {
267+
pickedFileList = <XFile>[];
268+
for (final String path in pathList) {
262269
pickedFileList.add(XFile(path));
263270
}
264271
}

packages/image_picker/image_picker_platform_interface/lib/src/platform_interface/image_picker_platform.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import 'dart:async';
66

77
import 'package:cross_file/cross_file.dart';
8-
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
98
import 'package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart';
109
import 'package:image_picker_platform_interface/src/types/types.dart';
10+
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1111

1212
/// The interface that implementations of image_picker must implement.
1313
///

packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/base.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import 'package:flutter/foundation.dart' show immutable;
1818
@immutable
1919
abstract class PickedFileBase {
2020
/// Construct a PickedFile
21-
PickedFileBase(String path);
21+
// ignore: avoid_unused_constructor_parameters
22+
const PickedFileBase(String path);
2223

2324
/// Get the path of the picked file.
2425
///

packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/html.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ import './base.dart';
1313
///
1414
/// It wraps the bytes of a selected file.
1515
class PickedFile extends PickedFileBase {
16-
final String path;
17-
final Uint8List? _initBytes;
18-
1916
/// Construct a PickedFile object from its ObjectUrl.
2017
///
2118
/// Optionally, this can be initialized with `bytes`
2219
/// so no http requests are performed to retrieve files later.
23-
PickedFile(this.path, {Uint8List? bytes})
20+
const PickedFile(this.path, {Uint8List? bytes})
2421
: _initBytes = bytes,
2522
super(path);
2623

24+
@override
25+
final String path;
26+
final Uint8List? _initBytes;
27+
2728
Future<Uint8List> get _bytes async {
2829
if (_initBytes != null) {
29-
return Future.value(UnmodifiableUint8ListView(_initBytes!));
30+
return Future<Uint8List>.value(UnmodifiableUint8ListView(_initBytes!));
3031
}
3132
return http.readBytes(Uri.parse(path));
3233
}
@@ -38,12 +39,12 @@ class PickedFile extends PickedFileBase {
3839

3940
@override
4041
Future<Uint8List> readAsBytes() async {
41-
return Future.value(await _bytes);
42+
return Future<Uint8List>.value(await _bytes);
4243
}
4344

4445
@override
4546
Stream<Uint8List> openRead([int? start, int? end]) async* {
46-
final bytes = await _bytes;
47+
final Uint8List bytes = await _bytes;
4748
yield bytes.sublist(start ?? 0, end ?? bytes.length);
4849
}
4950
}

packages/image_picker/image_picker_platform_interface/lib/src/types/picked_file/io.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import './base.dart';
1010

1111
/// A PickedFile backed by a dart:io File.
1212
class PickedFile extends PickedFileBase {
13-
final File _file;
14-
1513
/// Construct a PickedFile object backed by a dart:io File.
1614
PickedFile(String path)
1715
: _file = File(path),
1816
super(path);
1917

18+
final File _file;
19+
2020
@override
2121
String get path {
2222
return _file.path;
@@ -36,6 +36,6 @@ class PickedFile extends PickedFileBase {
3636
Stream<Uint8List> openRead([int? start, int? end]) {
3737
return _file
3838
.openRead(start ?? 0, end)
39-
.map((chunk) => Uint8List.fromList(chunk));
39+
.map((List<int> chunk) => Uint8List.fromList(chunk));
4040
}
4141
}

packages/image_picker/image_picker_platform_interface/lib/src/types/types.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
export 'camera_device.dart';
66
export 'image_source.dart';
7-
export 'retrieve_type.dart';
8-
export 'picked_file/picked_file.dart';
97
export 'lost_data_response.dart';
8+
export 'picked_file/picked_file.dart';
9+
export 'retrieve_type.dart';
1010

1111
/// Denotes that an image is being picked.
1212
const String kTypeImage = 'image';

packages/image_picker/image_picker_platform_interface/pubspec.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@ repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/i
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.4.3
7+
version: 2.4.4
88

99
environment:
1010
sdk: ">=2.12.0 <3.0.0"
1111
flutter: ">=2.0.0"
1212

1313
dependencies:
14+
cross_file: ^0.3.1+1
1415
flutter:
1516
sdk: flutter
1617
http: ^0.13.0
1718
plugin_platform_interface: ^2.1.0
18-
cross_file: ^0.3.1+1
1919

2020
dev_dependencies:
2121
flutter_test:
2222
sdk: flutter
23-
pedantic: ^1.10.0

0 commit comments

Comments
 (0)