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

[image_picker_platform_interface] use XFile instead of PickedFile #3388

Closed
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.0.0

**breaking changes**:
- pickImage now returns XFile instead of PickedFile
- pickVideo now returns XFile instead of PickedFile
- changed LostData file parameter type to XFile
- removed PickedFile class and its tests

balvinderz marked this conversation as resolved.
Show resolved Hide resolved
## 1.1.5

* Update Flutter SDK constraint.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export 'package:image_picker_platform_interface/src/platform_interface/image_picker_platform.dart';
export 'package:image_picker_platform_interface/src/types/types.dart';
export 'package:cross_file/cross_file.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:image_picker_platform_interface/src/types/lost_data.dart';
import 'package:meta/meta.dart' show required, visibleForTesting;

import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
Expand All @@ -20,7 +21,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
MethodChannel get channel => _channel;

@override
Future<PickedFile> pickImage({
Future<XFile> pickImage({
@required ImageSource source,
double maxWidth,
double maxHeight,
Expand All @@ -34,7 +35,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
imageQuality: imageQuality,
preferredCameraDevice: preferredCameraDevice,
);
return path != null ? PickedFile(path) : null;
return path != null ? XFile(path) : null;
}

@override
Expand Down Expand Up @@ -72,7 +73,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
}

@override
Future<PickedFile> pickVideo({
Future<XFile> pickVideo({
@required ImageSource source,
CameraDevice preferredCameraDevice = CameraDevice.rear,
Duration maxDuration,
Expand All @@ -82,7 +83,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
maxDuration: maxDuration,
preferredCameraDevice: preferredCameraDevice,
);
return path != null ? PickedFile(path) : null;
return path != null ? XFile(path) : null;
}

@override
Expand Down Expand Up @@ -132,7 +133,7 @@ class MethodChannelImagePicker extends ImagePickerPlatform {
final String path = result['path'];

return LostData(
file: path != null ? PickedFile(path) : null,
file: path != null ? XFile(path) : null,
exception: exception,
type: retrieveType,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import 'dart:async';

import 'package:cross_file/cross_file.dart';
import 'package:image_picker_platform_interface/src/types/lost_data.dart';
import 'package:meta/meta.dart' show required;
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

Expand Down Expand Up @@ -115,7 +117,7 @@ abstract class ImagePickerPlatform extends PlatformInterface {

// Next version of the API.

/// Returns a [PickedFile] with the image that was picked.
/// Returns a [XFile] with the image that was picked.
///
/// The `source` argument controls where the image comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
Expand All @@ -141,7 +143,7 @@ abstract class ImagePickerPlatform extends PlatformInterface {
///
/// In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
Future<PickedFile> pickImage({
Future<XFile> pickImage({
@required ImageSource source,
double maxWidth,
double maxHeight,
Expand All @@ -151,7 +153,7 @@ abstract class ImagePickerPlatform extends PlatformInterface {
throw UnimplementedError('pickImage() has not been implemented.');
}

/// Returns a [PickedFile] containing the video that was picked.
/// Returns a [XFile] containing the video that was picked.
///
/// The [source] argument controls where the video comes from. This can
/// be either [ImageSource.camera] or [ImageSource.gallery].
Expand All @@ -165,15 +167,15 @@ abstract class ImagePickerPlatform extends PlatformInterface {
///
/// In Android, the MainActivity can be destroyed for various fo reasons. If that happens, the result will be lost
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
Future<PickedFile> pickVideo({
Future<XFile> pickVideo({
@required ImageSource source,
CameraDevice preferredCameraDevice = CameraDevice.rear,
Duration maxDuration,
}) {
throw UnimplementedError('pickVideo() has not been implemented.');
}

/// Retrieve the lost [PickedFile] file when [pickImage] or [pickVideo] failed because the MainActivity is destroyed. (Android only)
/// Retrieve the lost [XFile] file when [pickImage] or [pickVideo] failed because the MainActivity is destroyed. (Android only)
///
/// Image or video can be lost if the MainActivity is destroyed. And there is no guarantee that the MainActivity is always alive.
/// Call this method to retrieve the lost data and process the data according to your APP's business logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:cross_file/cross_file.dart';
import 'package:flutter/services.dart';
import 'package:image_picker_platform_interface/src/types/types.dart';

Expand Down Expand Up @@ -31,7 +32,7 @@ class LostData {
/// The file that was lost in a previous [pickImage] or [pickVideo] call due to MainActivity being destroyed.
///
/// Can be null if [exception] exists.
final PickedFile file;
final XFile file;

/// The exception of the last [pickImage] or [pickVideo].
///
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export 'camera_device.dart';
export 'image_source.dart';
export 'lost_data_response.dart';
export 'retrieve_type.dart';
export 'picked_file/picked_file.dart';
export 'lost_data.dart';

/// Denotes that an image is being picked.
const String kTypeImage = 'image';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ description: A common platform interface for the image_picker plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.1.5
version: 2.0.0

dependencies:
flutter:
sdk: flutter
meta: ^1.1.8
http: ^0.12.1
plugin_platform_interface: ^1.0.2
cross_file: ^0.2.0

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_test/flutter_test.dart';

import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';
import 'package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart';
import 'package:image_picker_platform_interface/src/types/lost_data.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down

This file was deleted.

Loading