Skip to content

Commit 37a037a

Browse files
authored
[image_picker] Switch to internal method channel (#491)
1 parent 4278acd commit 37a037a

File tree

5 files changed

+156
-5
lines changed

5 files changed

+156
-5
lines changed

packages/image_picker/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.2.0
2+
3+
* Switch to an internal method channel implementation.
4+
* Unsupport deprecated methods.
5+
16
## 2.1.1
27

38
* Update image_picker to 0.8.6.

packages/image_picker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To use this plugin, add `image_picker` and `image_picker_tizen` as [dependencies
1111
```yaml
1212
dependencies:
1313
image_picker: ^0.8.6
14-
image_picker_tizen: ^2.1.1
14+
image_picker_tizen: ^2.2.0
1515
```
1616
1717
Then you can import `image_picker` in your Dart code.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:flutter/services.dart';
8+
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
9+
10+
const MethodChannel _channel =
11+
MethodChannel('plugins.flutter.io/image_picker_tizen');
12+
13+
/// A Tizen implementation of [ImagePickerPlatform].
14+
class ImagePickerTizen extends ImagePickerPlatform {
15+
/// Registers this class as the default platform implementation.
16+
static void register() {
17+
ImagePickerPlatform.instance = ImagePickerTizen();
18+
}
19+
20+
@override
21+
Future<XFile?> getImageFromSource({
22+
required ImageSource source,
23+
ImagePickerOptions options = const ImagePickerOptions(),
24+
}) async {
25+
final String? path = await _getImagePath(
26+
source: source,
27+
maxHeight: options.maxHeight,
28+
maxWidth: options.maxWidth,
29+
imageQuality: options.imageQuality,
30+
preferredCameraDevice: options.preferredCameraDevice,
31+
requestFullMetadata: options.requestFullMetadata,
32+
);
33+
return path != null ? XFile(path) : null;
34+
}
35+
36+
Future<String?> _getImagePath({
37+
required ImageSource source,
38+
double? maxWidth,
39+
double? maxHeight,
40+
int? imageQuality,
41+
CameraDevice preferredCameraDevice = CameraDevice.rear,
42+
bool requestFullMetadata = true,
43+
}) {
44+
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
45+
throw ArgumentError.value(
46+
imageQuality, 'imageQuality', 'must be between 0 and 100');
47+
}
48+
49+
if (maxWidth != null && maxWidth < 0) {
50+
throw ArgumentError.value(maxWidth, 'maxWidth', 'cannot be negative');
51+
}
52+
53+
if (maxHeight != null && maxHeight < 0) {
54+
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
55+
}
56+
57+
return _channel.invokeMethod<String>(
58+
'pickImage',
59+
<String, dynamic>{
60+
'source': source.index,
61+
'maxWidth': maxWidth,
62+
'maxHeight': maxHeight,
63+
'imageQuality': imageQuality,
64+
'cameraDevice': preferredCameraDevice.index,
65+
'requestFullMetadata': requestFullMetadata,
66+
},
67+
);
68+
}
69+
70+
@override
71+
Future<List<XFile>> getMultiImageWithOptions({
72+
MultiImagePickerOptions options = const MultiImagePickerOptions(),
73+
}) async {
74+
final List<dynamic>? paths = await _getMultiImagePath(
75+
maxWidth: options.imageOptions.maxWidth,
76+
maxHeight: options.imageOptions.maxHeight,
77+
imageQuality: options.imageOptions.imageQuality,
78+
requestFullMetadata: options.imageOptions.requestFullMetadata,
79+
);
80+
if (paths == null) {
81+
return <XFile>[];
82+
}
83+
84+
return paths.map((dynamic path) => XFile(path as String)).toList();
85+
}
86+
87+
Future<List<dynamic>?> _getMultiImagePath({
88+
double? maxWidth,
89+
double? maxHeight,
90+
int? imageQuality,
91+
bool requestFullMetadata = true,
92+
}) {
93+
if (imageQuality != null && (imageQuality < 0 || imageQuality > 100)) {
94+
throw ArgumentError.value(
95+
imageQuality, 'imageQuality', 'must be between 0 and 100');
96+
}
97+
98+
if (maxWidth != null && maxWidth < 0) {
99+
throw ArgumentError.value(maxWidth, 'maxWidth', 'cannot be negative');
100+
}
101+
102+
if (maxHeight != null && maxHeight < 0) {
103+
throw ArgumentError.value(maxHeight, 'maxHeight', 'cannot be negative');
104+
}
105+
106+
return _channel.invokeMethod<List<dynamic>?>(
107+
'pickMultiImage',
108+
<String, dynamic>{
109+
'maxWidth': maxWidth,
110+
'maxHeight': maxHeight,
111+
'imageQuality': imageQuality,
112+
'requestFullMetadata': requestFullMetadata,
113+
},
114+
);
115+
}
116+
117+
@override
118+
Future<XFile?> getVideo({
119+
required ImageSource source,
120+
CameraDevice preferredCameraDevice = CameraDevice.rear,
121+
Duration? maxDuration,
122+
}) async {
123+
final String? path = await _getVideoPath(
124+
source: source,
125+
maxDuration: maxDuration,
126+
preferredCameraDevice: preferredCameraDevice,
127+
);
128+
return path != null ? XFile(path) : null;
129+
}
130+
131+
Future<String?> _getVideoPath({
132+
required ImageSource source,
133+
CameraDevice preferredCameraDevice = CameraDevice.rear,
134+
Duration? maxDuration,
135+
}) {
136+
return _channel.invokeMethod<String>(
137+
'pickVideo',
138+
<String, dynamic>{
139+
'source': source.index,
140+
'maxDuration': maxDuration?.inSeconds,
141+
'cameraDevice': preferredCameraDevice.index
142+
},
143+
);
144+
}
145+
}

packages/image_picker/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: image_picker_tizen
2-
description: Flutter plugin for selecting images from the Tizen image
3-
library, and taking new pictures with the camera.
2+
description: Tizen implementation of the image_picker plugin.
3+
Used for picking images from the image library.
44
homepage: https://github.com/flutter-tizen/plugins
55
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/image_picker
6-
version: 2.1.1
6+
version: 2.2.0
77

88
flutter:
99
plugin:
1010
platforms:
1111
tizen:
1212
pluginClass: ImagePickerTizenPlugin
1313
fileName: image_picker_tizen_plugin.h
14+
dartPluginClass: ImagePickerTizen
1415

1516
dependencies:
1617
flutter:

packages/image_picker/tizen/src/image_picker_tizen_plugin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ImagePickerTizenPlugin : public flutter::Plugin {
4444
static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) {
4545
auto channel =
4646
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
47-
registrar->messenger(), "plugins.flutter.io/image_picker",
47+
registrar->messenger(), "plugins.flutter.io/image_picker_tizen",
4848
&flutter::StandardMethodCodec::GetInstance());
4949

5050
auto plugin = std::make_unique<ImagePickerTizenPlugin>();

0 commit comments

Comments
 (0)