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

Commit eb330b0

Browse files
[image_picker] Update app-facing and web analysis options (#4838)
1 parent 136f49b commit eb330b0

19 files changed

+223
-196
lines changed

packages/image_picker/image_picker/CHANGELOG.md

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

37
* Configures the `UIImagePicker` to default to gallery instead of camera when

packages/image_picker/image_picker/analysis_options.yaml

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

packages/image_picker/image_picker/example/lib/main.dart

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ void main() {
1919
class MyApp extends StatelessWidget {
2020
@override
2121
Widget build(BuildContext context) {
22-
return MaterialApp(
22+
return const MaterialApp(
2323
title: 'Image Picker Demo',
2424
home: MyHomePage(title: 'Image Picker Example'),
2525
);
2626
}
2727
}
2828

2929
class MyHomePage extends StatefulWidget {
30-
MyHomePage({Key? key, this.title}) : super(key: key);
30+
const MyHomePage({Key? key, this.title}) : super(key: key);
3131

3232
final String? title;
3333

@@ -39,7 +39,7 @@ class _MyHomePageState extends State<MyHomePage> {
3939
List<XFile>? _imageFileList;
4040

4141
set _imageFile(XFile? value) {
42-
_imageFileList = value == null ? null : [value];
42+
_imageFileList = value == null ? null : <XFile>[value];
4343
}
4444

4545
dynamic _pickImageError;
@@ -69,7 +69,7 @@ class _MyHomePageState extends State<MyHomePage> {
6969
// Mute the video so it auto-plays in web!
7070
// This is not needed if the call to .play is the result of user
7171
// interaction (clicking on a "play" button, for example).
72-
final double volume = kIsWeb ? 0.0 : 1.0;
72+
const double volume = kIsWeb ? 0.0 : 1.0;
7373
await controller.setVolume(volume);
7474
await controller.initialize();
7575
await controller.setLooping(true);
@@ -78,7 +78,7 @@ class _MyHomePageState extends State<MyHomePage> {
7878
}
7979
}
8080

81-
void _onImageButtonPressed(ImageSource source,
81+
Future<void> _onImageButtonPressed(ImageSource source,
8282
{BuildContext? context, bool isMultiImage = false}) async {
8383
if (_controller != null) {
8484
await _controller!.setVolume(0.0);
@@ -91,7 +91,7 @@ class _MyHomePageState extends State<MyHomePage> {
9191
await _displayPickImageDialog(context!,
9292
(double? maxWidth, double? maxHeight, int? quality) async {
9393
try {
94-
final pickedFileList = await _picker.pickMultiImage(
94+
final List<XFile>? pickedFileList = await _picker.pickMultiImage(
9595
maxWidth: maxWidth,
9696
maxHeight: maxHeight,
9797
imageQuality: quality,
@@ -109,7 +109,7 @@ class _MyHomePageState extends State<MyHomePage> {
109109
await _displayPickImageDialog(context!,
110110
(double? maxWidth, double? maxHeight, int? quality) async {
111111
try {
112-
final pickedFile = await _picker.pickImage(
112+
final XFile? pickedFile = await _picker.pickImage(
113113
source: source,
114114
maxWidth: maxWidth,
115115
maxHeight: maxHeight,
@@ -179,7 +179,7 @@ class _MyHomePageState extends State<MyHomePage> {
179179
return Semantics(
180180
child: ListView.builder(
181181
key: UniqueKey(),
182-
itemBuilder: (context, index) {
182+
itemBuilder: (BuildContext context, int index) {
183183
// Why network for web?
184184
// See https://pub.dev/packages/image_picker#getting-ready-for-the-web-platform
185185
return Semantics(
@@ -358,28 +358,30 @@ class _MyHomePageState extends State<MyHomePage> {
358358
BuildContext context, OnPickImageCallback onPick) async {
359359
return showDialog(
360360
context: context,
361-
builder: (context) {
361+
builder: (BuildContext context) {
362362
return AlertDialog(
363-
title: Text('Add optional parameters'),
363+
title: const Text('Add optional parameters'),
364364
content: Column(
365365
children: <Widget>[
366366
TextField(
367367
controller: maxWidthController,
368-
keyboardType: TextInputType.numberWithOptions(decimal: true),
369-
decoration:
370-
InputDecoration(hintText: "Enter maxWidth if desired"),
368+
keyboardType:
369+
const TextInputType.numberWithOptions(decimal: true),
370+
decoration: const InputDecoration(
371+
hintText: 'Enter maxWidth if desired'),
371372
),
372373
TextField(
373374
controller: maxHeightController,
374-
keyboardType: TextInputType.numberWithOptions(decimal: true),
375-
decoration:
376-
InputDecoration(hintText: "Enter maxHeight if desired"),
375+
keyboardType:
376+
const TextInputType.numberWithOptions(decimal: true),
377+
decoration: const InputDecoration(
378+
hintText: 'Enter maxHeight if desired'),
377379
),
378380
TextField(
379381
controller: qualityController,
380382
keyboardType: TextInputType.number,
381-
decoration:
382-
InputDecoration(hintText: "Enter quality if desired"),
383+
decoration: const InputDecoration(
384+
hintText: 'Enter quality if desired'),
383385
),
384386
],
385387
),
@@ -393,13 +395,13 @@ class _MyHomePageState extends State<MyHomePage> {
393395
TextButton(
394396
child: const Text('PICK'),
395397
onPressed: () {
396-
double? width = maxWidthController.text.isNotEmpty
398+
final double? width = maxWidthController.text.isNotEmpty
397399
? double.parse(maxWidthController.text)
398400
: null;
399-
double? height = maxHeightController.text.isNotEmpty
401+
final double? height = maxHeightController.text.isNotEmpty
400402
? double.parse(maxHeightController.text)
401403
: null;
402-
int? quality = qualityController.text.isNotEmpty
404+
final int? quality = qualityController.text.isNotEmpty
403405
? int.parse(qualityController.text)
404406
: null;
405407
onPick(width, height, quality);
@@ -411,11 +413,11 @@ class _MyHomePageState extends State<MyHomePage> {
411413
}
412414
}
413415

414-
typedef void OnPickImageCallback(
416+
typedef OnPickImageCallback = void Function(
415417
double? maxWidth, double? maxHeight, int? quality);
416418

417419
class AspectRatioVideo extends StatefulWidget {
418-
AspectRatioVideo(this.controller);
420+
const AspectRatioVideo(this.controller);
419421

420422
final VideoPlayerController? controller;
421423

packages/image_picker/image_picker/example/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ environment:
77
flutter: ">=2.5.0"
88

99
dependencies:
10-
video_player: ^2.1.4
1110
flutter:
1211
sdk: flutter
1312
flutter_plugin_android_lifecycle: ^2.0.1
@@ -18,14 +17,14 @@ dependencies:
1817
# The example app is bundled with the plugin so we use a path dependency on
1918
# the parent directory to use the current plugin's version.
2019
path: ../
20+
video_player: ^2.1.4
2121

2222
dev_dependencies:
2323
espresso: ^0.1.0+2
2424
flutter_driver:
2525
sdk: flutter
2626
integration_test:
2727
sdk: flutter
28-
pedantic: ^1.10.0
2928

3029
flutter:
3130
uses-material-design: true

packages/image_picker/image_picker/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
33
library, and taking new pictures with the camera.
44
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
6-
version: 0.8.4+8
6+
version: 0.8.4+9
77

88
environment:
99
sdk: ">=2.14.0 <3.0.0"
@@ -31,5 +31,4 @@ dev_dependencies:
3131
flutter_test:
3232
sdk: flutter
3333
mockito: ^5.0.0
34-
pedantic: ^1.10.0
3534
plugin_platform_interface: ^2.0.0

packages/image_picker/image_picker/test/image_picker_deprecated_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void main() {
2323

2424
final List<MethodCall> log = <MethodCall>[];
2525

26-
final picker = ImagePicker();
26+
final ImagePicker picker = ImagePicker();
2727

2828
test('ImagePicker platform instance overrides the actual platform used',
2929
() {
@@ -359,7 +359,7 @@ void main() {
359359
setUp(() {
360360
channel.setMockMethodCallHandler((MethodCall methodCall) async {
361361
log.add(methodCall);
362-
return [];
362+
return <dynamic>[];
363363
});
364364
log.clear();
365365
});

packages/image_picker/image_picker/test/image_picker_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main() {
1818

1919
final List<MethodCall> log = <MethodCall>[];
2020

21-
final picker = ImagePicker();
21+
final ImagePicker picker = ImagePicker();
2222

2323
test('ImagePicker platform instance overrides the actual platform used',
2424
() {
@@ -321,7 +321,7 @@ void main() {
321321
return <String, dynamic>{
322322
'type': 'image',
323323
'path': '/example/path1',
324-
'pathList': ['/example/path0', '/example/path1'],
324+
'pathList': <dynamic>['/example/path0', '/example/path1'],
325325
};
326326
});
327327

@@ -372,7 +372,7 @@ void main() {
372372
setUp(() {
373373
channel.setMockMethodCallHandler((MethodCall methodCall) async {
374374
log.add(methodCall);
375-
return [];
375+
return <dynamic>[];
376376
});
377377
log.clear();
378378
});

packages/image_picker/image_picker_for_web/CHANGELOG.md

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

37
* Removes dependency on `meta`.

packages/image_picker/image_picker_for_web/analysis_options.yaml

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

packages/image_picker/image_picker_for_web/example/integration_test/image_picker_for_web_test.dart

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ import 'package:image_picker_for_web/image_picker_for_web.dart';
1111
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
1212
import 'package:integration_test/integration_test.dart';
1313

14-
final String expectedStringContents = 'Hello, world!';
15-
final String otherStringContents = 'Hello again, world!';
14+
const String expectedStringContents = 'Hello, world!';
15+
const String otherStringContents = 'Hello again, world!';
1616
final Uint8List bytes = utf8.encode(expectedStringContents) as Uint8List;
1717
final Uint8List otherBytes = utf8.encode(otherStringContents) as Uint8List;
18-
final Map<String, dynamic> options = {
18+
final Map<String, dynamic> options = <String, dynamic>{
1919
'type': 'text/plain',
2020
'lastModified': DateTime.utc(2017, 12, 13).millisecondsSinceEpoch,
2121
};
22-
final html.File textFile = html.File([bytes], 'hello.txt', options);
23-
final html.File secondTextFile = html.File([otherBytes], 'secondFile.txt');
22+
final html.File textFile = html.File(<Uint8List>[bytes], 'hello.txt', options);
23+
final html.File secondTextFile =
24+
html.File(<Uint8List>[otherBytes], 'secondFile.txt');
2425

2526
void main() {
2627
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
@@ -33,16 +34,17 @@ void main() {
3334
});
3435

3536
testWidgets('Can select a file (Deprecated)', (WidgetTester tester) async {
36-
final mockInput = html.FileUploadInputElement();
37+
final html.FileUploadInputElement mockInput = html.FileUploadInputElement();
3738

38-
final overrides = ImagePickerPluginTestOverrides()
39-
..createInputElement = ((_, __) => mockInput)
40-
..getMultipleFilesFromInput = ((_) => [textFile]);
39+
final ImagePickerPluginTestOverrides overrides =
40+
ImagePickerPluginTestOverrides()
41+
..createInputElement = ((_, __) => mockInput)
42+
..getMultipleFilesFromInput = ((_) => <html.File>[textFile]);
4143

42-
final plugin = ImagePickerPlugin(overrides: overrides);
44+
final ImagePickerPlugin plugin = ImagePickerPlugin(overrides: overrides);
4345

4446
// Init the pick file dialog...
45-
final file = plugin.pickFile();
47+
final Future<PickedFile> file = plugin.pickFile();
4648

4749
// Mock the browser behavior of selecting a file...
4850
mockInput.dispatchEvent(html.Event('change'));
@@ -54,16 +56,17 @@ void main() {
5456
});
5557

5658
testWidgets('Can select a file', (WidgetTester tester) async {
57-
final mockInput = html.FileUploadInputElement();
59+
final html.FileUploadInputElement mockInput = html.FileUploadInputElement();
5860

59-
final overrides = ImagePickerPluginTestOverrides()
60-
..createInputElement = ((_, __) => mockInput)
61-
..getMultipleFilesFromInput = ((_) => [textFile]);
61+
final ImagePickerPluginTestOverrides overrides =
62+
ImagePickerPluginTestOverrides()
63+
..createInputElement = ((_, __) => mockInput)
64+
..getMultipleFilesFromInput = ((_) => <html.File>[textFile]);
6265

63-
final plugin = ImagePickerPlugin(overrides: overrides);
66+
final ImagePickerPlugin plugin = ImagePickerPlugin(overrides: overrides);
6467

6568
// Init the pick file dialog...
66-
final image = plugin.getImage(source: ImageSource.camera);
69+
final Future<XFile> image = plugin.getImage(source: ImageSource.camera);
6770

6871
// Mock the browser behavior of selecting a file...
6972
mockInput.dispatchEvent(html.Event('change'));
@@ -85,16 +88,18 @@ void main() {
8588
});
8689

8790
testWidgets('Can select multiple files', (WidgetTester tester) async {
88-
final mockInput = html.FileUploadInputElement();
91+
final html.FileUploadInputElement mockInput = html.FileUploadInputElement();
8992

90-
final overrides = ImagePickerPluginTestOverrides()
91-
..createInputElement = ((_, __) => mockInput)
92-
..getMultipleFilesFromInput = ((_) => [textFile, secondTextFile]);
93+
final ImagePickerPluginTestOverrides overrides =
94+
ImagePickerPluginTestOverrides()
95+
..createInputElement = ((_, __) => mockInput)
96+
..getMultipleFilesFromInput =
97+
((_) => <html.File>[textFile, secondTextFile]);
9398

94-
final plugin = ImagePickerPlugin(overrides: overrides);
99+
final ImagePickerPlugin plugin = ImagePickerPlugin(overrides: overrides);
95100

96101
// Init the pick file dialog...
97-
final files = plugin.getMultiImage();
102+
final Future<List<XFile>> files = plugin.getMultiImage();
98103

99104
// Mock the browser behavior of selecting a file...
100105
mockInput.dispatchEvent(html.Event('change'));
@@ -135,15 +140,15 @@ void main() {
135140

136141
group('createInputElement', () {
137142
testWidgets('accept: any, capture: null', (WidgetTester tester) async {
138-
html.Element input = plugin.createInputElement('any', null);
143+
final html.Element input = plugin.createInputElement('any', null);
139144

140145
expect(input.attributes, containsPair('accept', 'any'));
141146
expect(input.attributes, isNot(contains('capture')));
142147
expect(input.attributes, isNot(contains('multiple')));
143148
});
144149

145150
testWidgets('accept: any, capture: something', (WidgetTester tester) async {
146-
html.Element input = plugin.createInputElement('any', 'something');
151+
final html.Element input = plugin.createInputElement('any', 'something');
147152

148153
expect(input.attributes, containsPair('accept', 'any'));
149154
expect(input.attributes, containsPair('capture', 'something'));
@@ -152,7 +157,7 @@ void main() {
152157

153158
testWidgets('accept: any, capture: null, multi: true',
154159
(WidgetTester tester) async {
155-
html.Element input =
160+
final html.Element input =
156161
plugin.createInputElement('any', null, multiple: true);
157162

158163
expect(input.attributes, containsPair('accept', 'any'));
@@ -162,7 +167,7 @@ void main() {
162167

163168
testWidgets('accept: any, capture: something, multi: true',
164169
(WidgetTester tester) async {
165-
html.Element input =
170+
final html.Element input =
166171
plugin.createInputElement('any', 'something', multiple: true);
167172

168173
expect(input.attributes, containsPair('accept', 'any'));

0 commit comments

Comments
 (0)