Skip to content

Commit

Permalink
[image_picker] Update image_picker to 0.8.4 (flutter-tizen#282)
Browse files Browse the repository at this point in the history
* [image_picker] Update image_picker to 0.8.4

* Fix cancelled by a second request
  • Loading branch information
swift-kim authored Dec 6, 2021
1 parent dddc2ab commit c5fab5d
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 179 deletions.
21 changes: 14 additions & 7 deletions packages/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
## 1.0.0

* Initial release
* Initial release.

## 2.0.0

* Update Dart and Flutter SDK constraints
* Update Flutter copyright information
* Update example and integration_test
* Port to use platform interface
* Update video_player to 2.0.2
* Organize dev_dependencies
* Update Dart and Flutter SDK constraints.
* Update Flutter copyright information.
* Update the example app and integration_test.
* Port to use platform interface.
* Organize dev_dependencies.

## 2.1.0

* Update image_picker to 0.8.4.
* Update image_picker_platform_interface to 2.4.1.
* Implement `pickMultiImage`.
* Update the example app.
* Minor cleanups.
28 changes: 15 additions & 13 deletions packages/image_picker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@ To use this plugin, add `image_picker` and `image_picker_tizen` as [dependencies

```yaml
dependencies:
image_picker: ^0.7.3
image_picker_tizen: ^2.0.0
image_picker: ^0.8.4
image_picker_tizen: ^2.1.0
```
## Example
Import the library.
Then you can import `image_picker` in your Dart code.

``` dart
import 'package:image_picker/image_picker.dart';
final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
```

Then invoke the static `image_picker` method anywhere in your Dart code.
For detailed usage, see https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker#example.

``` dart
final picker = ImagePicker();
final pickedFile = await picker.getImage(source: ImageSource.gallery);
```
## Supported devices

- Galaxy Watch series (running Tizen 5.5 or later)

## Limitations
## Supported APIs

- This plugin is only supported on **Galaxy Watch** devices running Tizen 5.5 or later.
- The only API you can use is `getImage(source: ImageSource.gallery)`. You can't pick a video file (`getVideo()`) or pick a file from `ImageSource.camera`.
- [x] `ImagePicker.pickImage` (only `ImageSource.gallery` is available as `source`)
- [x] `ImagePicker.pickMultiImage`
- [ ] `ImagePicker.pickVideo` (no file manager app available)
- [ ] `ImagePicker.retrieveLostData` (Android-only)

## Required privileges

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

// @dart=2.9

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('placeholder test', (WidgetTester tester) async {});
}
141 changes: 85 additions & 56 deletions packages/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 const MaterialApp(
return MaterialApp(
title: 'Image Picker Demo',
home: MyHomePage(title: 'Image Picker Example'),
);
}
}

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

final String? title;

Expand All @@ -36,9 +36,15 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
PickedFile? _imageFile;
List<XFile>? _imageFileList;

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

dynamic _pickImageError;
bool isVideo = false;

VideoPlayerController? _controller;
VideoPlayerController? _toBeDisposed;
String? _retrieveDataError;
Expand All @@ -48,7 +54,7 @@ class _MyHomePageState extends State<MyHomePage> {
final TextEditingController maxHeightController = TextEditingController();
final TextEditingController qualityController = TextEditingController();

Future<void> _playVideo(PickedFile? file) async {
Future<void> _playVideo(XFile? file) async {
if (file != null && mounted) {
await _disposeVideoController();
late VideoPlayerController controller;
Expand All @@ -72,20 +78,38 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

Future<void> _onImageButtonPressed(ImageSource source,
{BuildContext? context}) async {
void _onImageButtonPressed(ImageSource source,
{BuildContext? context, bool isMultiImage = false}) async {
if (_controller != null) {
await _controller!.setVolume(0.0);
}
if (isVideo) {
final PickedFile? file = await _picker.getVideo(
final XFile? file = await _picker.pickVideo(
source: source, maxDuration: const Duration(seconds: 10));
await _playVideo(file);
} else if (isMultiImage) {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final pickedFileList = await _picker.pickMultiImage(
maxWidth: maxWidth,
maxHeight: maxHeight,
imageQuality: quality,
);
setState(() {
_imageFileList = pickedFileList;
});
} catch (e) {
setState(() {
_pickImageError = e;
});
}
});
} else {
await _displayPickImageDialog(context!,
(double? maxWidth, double? maxHeight, int? quality) async {
try {
final PickedFile? pickedFile = await _picker.getImage(
final pickedFile = await _picker.pickImage(
source: source,
maxWidth: maxWidth,
maxHeight: maxHeight,
Expand Down Expand Up @@ -146,21 +170,28 @@ class _MyHomePageState extends State<MyHomePage> {
);
}

Widget _previewImage() {
Widget _previewImages() {
final Text? retrieveError = _getRetrieveErrorWidget();
if (retrieveError != null) {
return retrieveError;
}
if (_imageFile != null) {
if (kIsWeb) {
// Why network?
// See https://pub.dev/packages/image_picker#getting-ready-for-the-web-platform
return Image.network(_imageFile!.path);
} else {
return Semantics(
child: Image.file(File(_imageFile!.path)),
label: 'image_picker_example_picked_image');
}
if (_imageFileList != null) {
return Semantics(
child: ListView.builder(
key: UniqueKey(),
itemBuilder: (context, index) {
// Why network for web?
// See https://pub.dev/packages/image_picker#getting-ready-for-the-web-platform
return Semantics(
label: 'image_picker_example_picked_image',
child: kIsWeb
? Image.network(_imageFileList![index].path)
: Image.file(File(_imageFileList![index].path)),
);
},
itemCount: _imageFileList!.length,
),
label: 'image_picker_example_picked_images');
} else if (_pickImageError != null) {
return Text(
'Pick image error: $_pickImageError',
Expand All @@ -174,8 +205,16 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

Widget _handlePreview() {
if (isVideo) {
return _previewVideo();
} else {
return _previewImages();
}
}

Future<void> retrieveLostData() async {
final LostData response = await _picker.getLostData();
final LostDataResponse response = await _picker.retrieveLostData();
if (response.isEmpty) {
return;
}
Expand All @@ -187,6 +226,7 @@ class _MyHomePageState extends State<MyHomePage> {
isVideo = false;
setState(() {
_imageFile = response.file;
_imageFileList = response.files;
});
}
} else {
Expand All @@ -213,7 +253,7 @@ class _MyHomePageState extends State<MyHomePage> {
textAlign: TextAlign.center,
);
case ConnectionState.done:
return isVideo ? _previewVideo() : _previewImage();
return _handlePreview();
default:
if (snapshot.hasError) {
return Text(
Expand All @@ -229,7 +269,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
},
)
: (isVideo ? _previewVideo() : _previewImage()),
: _handlePreview(),
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
Expand All @@ -243,19 +283,23 @@ class _MyHomePageState extends State<MyHomePage> {
},
heroTag: 'image0',
tooltip: 'Pick Image from gallery',
child: const Icon(Icons.photo_library),
child: const Icon(Icons.photo),
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: FloatingActionButton(
onPressed: () {
isVideo = false;
_onImageButtonPressed(ImageSource.camera, context: context);
_onImageButtonPressed(
ImageSource.gallery,
context: context,
isMultiImage: true,
);
},
heroTag: 'image1',
tooltip: 'Take a Photo',
child: const Icon(Icons.camera_alt),
tooltip: 'Pick Multiple Image from gallery',
child: const Icon(Icons.photo_library),
),
),
Padding(
Expand All @@ -271,19 +315,6 @@ class _MyHomePageState extends State<MyHomePage> {
child: const Icon(Icons.video_library),
),
),
Padding(
padding: const EdgeInsets.only(top: 16.0),
child: FloatingActionButton(
backgroundColor: Colors.red,
onPressed: () {
isVideo = true;
_onImageButtonPressed(ImageSource.camera);
},
heroTag: 'video1',
tooltip: 'Take a Video',
child: const Icon(Icons.videocam),
),
),
],
),
);
Expand All @@ -302,30 +333,28 @@ class _MyHomePageState extends State<MyHomePage> {
BuildContext context, OnPickImageCallback onPick) async {
return showDialog(
context: context,
builder: (BuildContext context) {
builder: (context) {
return AlertDialog(
title: const Text('Add optional parameters'),
title: Text('Add optional parameters'),
content: Column(
children: <Widget>[
TextField(
controller: maxWidthController,
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
decoration: const InputDecoration(
hintText: 'Enter maxWidth if desired'),
keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration:
InputDecoration(hintText: "Enter maxWidth if desired"),
),
TextField(
controller: maxHeightController,
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
decoration: const InputDecoration(
hintText: 'Enter maxHeight if desired'),
keyboardType: TextInputType.numberWithOptions(decimal: true),
decoration:
InputDecoration(hintText: "Enter maxHeight if desired"),
),
TextField(
controller: qualityController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
hintText: 'Enter quality if desired'),
decoration:
InputDecoration(hintText: "Enter quality if desired"),
),
],
),
Expand All @@ -339,13 +368,13 @@ class _MyHomePageState extends State<MyHomePage> {
TextButton(
child: const Text('PICK'),
onPressed: () {
final double? width = maxWidthController.text.isNotEmpty
double? width = maxWidthController.text.isNotEmpty
? double.parse(maxWidthController.text)
: null;
final double? height = maxHeightController.text.isNotEmpty
double? height = maxHeightController.text.isNotEmpty
? double.parse(maxHeightController.text)
: null;
final int? quality = qualityController.text.isNotEmpty
int? quality = qualityController.text.isNotEmpty
? int.parse(qualityController.text)
: null;
onPick(width, height, quality);
Expand All @@ -357,11 +386,11 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

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

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

final VideoPlayerController? controller;

Expand Down
4 changes: 2 additions & 2 deletions packages/image_picker/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ publish_to: "none"
dependencies:
flutter:
sdk: flutter
image_picker: ^0.7.3
image_picker: ^0.8.4
image_picker_tizen:
path: ../
video_player: ^2.0.2
video_player: ^2.1.4

dev_dependencies:
flutter_driver:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
Loading

0 comments on commit c5fab5d

Please sign in to comment.