|
| 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 | +} |
0 commit comments