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

[image_picker] Update app-facing and web analysis options #4838

Merged
merged 8 commits into from
Feb 16, 2022
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
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.4+9

* Internal code cleanup for stricter analysis options.

## 0.8.4+8

* Configures the `UIImagePicker` to default to gallery instead of camera when
Expand Down
1 change: 0 additions & 1 deletion packages/image_picker/image_picker/analysis_options.yaml

This file was deleted.

48 changes: 25 additions & 23 deletions packages/image_picker/image_picker/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ void main() {
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
title: 'Image Picker Demo',
home: MyHomePage(title: 'Image Picker Example'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, this.title}) : super(key: key);
const MyHomePage({Key? key, this.title}) : super(key: key);

final String? title;

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

set _imageFile(XFile? value) {
_imageFileList = value == null ? null : [value];
_imageFileList = value == null ? null : <XFile>[value];
}

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

void _onImageButtonPressed(ImageSource source,
Future<void> _onImageButtonPressed(ImageSource source,
{BuildContext? context, bool isMultiImage = false}) async {
if (_controller != null) {
await _controller!.setVolume(0.0);
Expand All @@ -91,7 +91,7 @@ class _MyHomePageState extends State<MyHomePage> {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final pickedFileList = await _picker.pickMultiImage(
final List<XFile>? pickedFileList = await _picker.pickMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: quality,
Expand All @@ -109,7 +109,7 @@ class _MyHomePageState extends State<MyHomePage> {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final pickedFile = await _picker.pickImage(
final XFile? pickedFile = await _picker.pickImage(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
Expand Down Expand Up @@ -179,7 +179,7 @@ class _MyHomePageState extends State<MyHomePage> {
return Semantics(
child: ListView.builder(
key: UniqueKey(),
itemBuilder: (context, index) {
itemBuilder: (BuildContext context, int index) {
// Why network for web?
// See https://pub.dev/packages/image_picker#getting-ready-for-the-web-platform
return Semantics(
Expand Down Expand Up @@ -358,28 +358,30 @@ class _MyHomePageState extends State<MyHomePage> {
BuildContext context, OnPickImageCallback onPick) async {
return showDialog(
context: context,
builder: (context) {
builder: (BuildContext context) {
return AlertDialog(
title: Text('Add optional parameters'),
title: const Text('Add optional parameters'),
content: Column(
children: <Widget>[
TextField(
controller: maxWidthController,
keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration:
InputDecoration(hintText: "Enter maxWidth if desired"),
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
decoration: const InputDecoration(
hintText: 'Enter maxWidth if desired'),
),
TextField(
controller: maxHeightController,
keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration:
InputDecoration(hintText: "Enter maxHeight if desired"),
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
decoration: const InputDecoration(
hintText: 'Enter maxHeight if desired'),
),
TextField(
controller: qualityController,
keyboardType: TextInputType.number,
decoration:
InputDecoration(hintText: "Enter quality if desired"),
decoration: const InputDecoration(
hintText: 'Enter quality if desired'),
),
],
),
Expand All @@ -393,13 +395,13 @@ class _MyHomePageState extends State<MyHomePage> {
TextButton(
child: const Text('PICK'),
onPressed: () {
double? width = maxWidthController.text.isNotEmpty
final double? width = maxWidthController.text.isNotEmpty
? double.parse(maxWidthController.text)
: null;
double? height = maxHeightController.text.isNotEmpty
final double? height = maxHeightController.text.isNotEmpty
? double.parse(maxHeightController.text)
: null;
int? quality = qualityController.text.isNotEmpty
final int? quality = qualityController.text.isNotEmpty
? int.parse(qualityController.text)
: null;
onPick(width, height, quality);
Expand All @@ -411,11 +413,11 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

typedef void OnPickImageCallback(
typedef OnPickImageCallback = void Function(
double? maxWidth, double? maxHeight, int? quality);

class AspectRatioVideo extends StatefulWidget {
AspectRatioVideo(this.controller);
const AspectRatioVideo(this.controller);

final VideoPlayerController? controller;

Expand Down
3 changes: 1 addition & 2 deletions packages/image_picker/image_picker/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ environment:
flutter: ">=2.5.0"

dependencies:
video_player: ^2.1.4
flutter:
sdk: flutter
flutter_plugin_android_lifecycle: ^2.0.1
Expand All @@ -18,14 +17,14 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
video_player: ^2.1.4

dev_dependencies:
espresso: ^0.1.0+2
flutter_driver:
sdk: flutter
integration_test:
sdk: flutter
pedantic: ^1.10.0

flutter:
uses-material-design: true
3 changes: 1 addition & 2 deletions packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
repository: https://github.com/flutter/plugins/tree/main/packages/image_picker/image_picker
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.4+8
version: 0.8.4+9

environment:
sdk: ">=2.14.0 <3.0.0"
Expand Down Expand Up @@ -31,5 +31,4 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.0.0
pedantic: ^1.10.0
plugin_platform_interface: ^2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {

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

final picker = ImagePicker();
final ImagePicker picker = ImagePicker();

test('ImagePicker platform instance overrides the actual platform used',
() {
Expand Down Expand Up @@ -359,7 +359,7 @@ void main() {
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
return [];
return <dynamic>[];
});
log.clear();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {

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

final picker = ImagePicker();
final ImagePicker picker = ImagePicker();

test('ImagePicker platform instance overrides the actual platform used',
() {
Expand Down Expand Up @@ -321,7 +321,7 @@ void main() {
return <String, dynamic>{
'type': 'image',
'path': '/example/path1',
'pathList': ['/example/path0', '/example/path1'],
'pathList': <dynamic>['/example/path0', '/example/path1'],
};
});

Expand Down Expand Up @@ -372,7 +372,7 @@ void main() {
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
return [];
return <dynamic>[];
});
log.clear();
});
Expand Down
4 changes: 4 additions & 0 deletions packages/image_picker/image_picker_for_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.6

* Internal code cleanup for stricter analysis options.

## 2.1.5

* Removes dependency on `meta`.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import 'package:image_picker_for_web/image_picker_for_web.dart';
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
import 'package:integration_test/integration_test.dart';

final String expectedStringContents = 'Hello, world!';
final String otherStringContents = 'Hello again, world!';
const String expectedStringContents = 'Hello, world!';
const String otherStringContents = 'Hello again, world!';
final Uint8List bytes = utf8.encode(expectedStringContents) as Uint8List;
final Uint8List otherBytes = utf8.encode(otherStringContents) as Uint8List;
final Map<String, dynamic> options = {
final Map<String, dynamic> options = <String, dynamic>{
'type': 'text/plain',
'lastModified': DateTime.utc(2017, 12, 13).millisecondsSinceEpoch,
};
final html.File textFile = html.File([bytes], 'hello.txt', options);
final html.File secondTextFile = html.File([otherBytes], 'secondFile.txt');
final html.File textFile = html.File(<Uint8List>[bytes], 'hello.txt', options);
final html.File secondTextFile =
html.File(<Uint8List>[otherBytes], 'secondFile.txt');

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Expand All @@ -33,16 +34,17 @@ void main() {
});

testWidgets('Can select a file (Deprecated)', (WidgetTester tester) async {
final mockInput = html.FileUploadInputElement();
final html.FileUploadInputElement mockInput = html.FileUploadInputElement();

final overrides = ImagePickerPluginTestOverrides()
..createInputElement = ((_, __) => mockInput)
..getMultipleFilesFromInput = ((_) => [textFile]);
final ImagePickerPluginTestOverrides overrides =
ImagePickerPluginTestOverrides()
..createInputElement = ((_, __) => mockInput)
..getMultipleFilesFromInput = ((_) => <html.File>[textFile]);

final plugin = ImagePickerPlugin(overrides: overrides);
final ImagePickerPlugin plugin = ImagePickerPlugin(overrides: overrides);

// Init the pick file dialog...
final file = plugin.pickFile();
final Future<PickedFile> file = plugin.pickFile();

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

testWidgets('Can select a file', (WidgetTester tester) async {
final mockInput = html.FileUploadInputElement();
final html.FileUploadInputElement mockInput = html.FileUploadInputElement();

final overrides = ImagePickerPluginTestOverrides()
..createInputElement = ((_, __) => mockInput)
..getMultipleFilesFromInput = ((_) => [textFile]);
final ImagePickerPluginTestOverrides overrides =
ImagePickerPluginTestOverrides()
..createInputElement = ((_, __) => mockInput)
..getMultipleFilesFromInput = ((_) => <html.File>[textFile]);

final plugin = ImagePickerPlugin(overrides: overrides);
final ImagePickerPlugin plugin = ImagePickerPlugin(overrides: overrides);

// Init the pick file dialog...
final image = plugin.getImage(source: ImageSource.camera);
final Future<XFile> image = plugin.getImage(source: ImageSource.camera);

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

testWidgets('Can select multiple files', (WidgetTester tester) async {
final mockInput = html.FileUploadInputElement();
final html.FileUploadInputElement mockInput = html.FileUploadInputElement();

final overrides = ImagePickerPluginTestOverrides()
..createInputElement = ((_, __) => mockInput)
..getMultipleFilesFromInput = ((_) => [textFile, secondTextFile]);
final ImagePickerPluginTestOverrides overrides =
ImagePickerPluginTestOverrides()
..createInputElement = ((_, __) => mockInput)
..getMultipleFilesFromInput =
((_) => <html.File>[textFile, secondTextFile]);

final plugin = ImagePickerPlugin(overrides: overrides);
final ImagePickerPlugin plugin = ImagePickerPlugin(overrides: overrides);

// Init the pick file dialog...
final files = plugin.getMultiImage();
final Future<List<XFile>> files = plugin.getMultiImage();

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

group('createInputElement', () {
testWidgets('accept: any, capture: null', (WidgetTester tester) async {
html.Element input = plugin.createInputElement('any', null);
final html.Element input = plugin.createInputElement('any', null);

expect(input.attributes, containsPair('accept', 'any'));
expect(input.attributes, isNot(contains('capture')));
expect(input.attributes, isNot(contains('multiple')));
});

testWidgets('accept: any, capture: something', (WidgetTester tester) async {
html.Element input = plugin.createInputElement('any', 'something');
final html.Element input = plugin.createInputElement('any', 'something');

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

testWidgets('accept: any, capture: null, multi: true',
(WidgetTester tester) async {
html.Element input =
final html.Element input =
plugin.createInputElement('any', null, multiple: true);

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

testWidgets('accept: any, capture: something, multi: true',
(WidgetTester tester) async {
html.Element input =
final html.Element input =
plugin.createInputElement('any', 'something', multiple: true);

expect(input.attributes, containsPair('accept', 'any'));
Expand Down
Loading