-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[image_picker] Add desktop support #3882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 35 commits into
flutter:main
from
stuartmorgan-g:image-picker-macos-linux
Jun 10, 2023
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a35167d
README fix
stuartmorgan-g 69dc81b
Direct copy of Windows
stuartmorgan-g b110acf
Remove Windows examples, add template-created macOS and Linux examples
stuartmorgan-g e311f04
Add new platform interface pieces
stuartmorgan-g 1558aa2
Update Windows implementation
stuartmorgan-g 9f0f245
Add macOS and Linux implementations
stuartmorgan-g e8e6c98
Add integration test config exemptions
stuartmorgan-g 5d8b155
Fix some lingering references to Windows
stuartmorgan-g fd7655d
Add TODO about PHFilePicker
stuartmorgan-g e48478e
Update desktop implementation examples to use newer APIs
stuartmorgan-g 047b32a
Fix macOS
stuartmorgan-g 4af92e2
Add app-facing API, update examples
stuartmorgan-g 1361f31
Add README notes, version bumps, and endorsement
stuartmorgan-g 094b763
Adjust labels
stuartmorgan-g c384211
Add codeowners
stuartmorgan-g ba3a86b
Update OS support table in README
stuartmorgan-g 3f0161a
Fix pubspec overrides
stuartmorgan-g 1d99ee1
Add desktop support to app-facing example
stuartmorgan-g 7a509e3
Copyright for template-generated files
stuartmorgan-g 471f87d
Revert auto-changes to existing platforms
stuartmorgan-g 42ac084
Sort overrides
stuartmorgan-g a2eb725
Autoformat boilerplate code
stuartmorgan-g 9174b4f
Add missing version bump
stuartmorgan-g 3e4b21c
Initial review comments
stuartmorgan-g 0281b4c
Remove examples for ease of review
stuartmorgan-g 4ada117
Reverts removing examples for ease of review
stuartmorgan-g 16ab8c2
Merge branch 'main' into image-picker-macos-linux
stuartmorgan-g 921e295
Merge branch 'main' into image-picker-macos-linux
stuartmorgan-g 7b4ebf5
Address review comments
stuartmorgan-g d18936d
Missing awaits
stuartmorgan-g 9296999
Merge branch 'main' into image-picker-macos-linux
stuartmorgan-g ff710c6
Scrub platform interface overrides
stuartmorgan-g c79601e
Merge branch 'main' into image-picker-macos-linux
stuartmorgan-g dba80d2
Remove overrides
stuartmorgan-g 6a86c5d
Update macOS version
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add new platform interface pieces
- Loading branch information
commit e311f04670264d91b2e9a2f76f1b4157ac7608b0
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/image_picker/image_picker_platform_interface/lib/src/types/camera_delegate.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // 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/foundation.dart' show immutable; | ||
|
|
||
| import 'camera_device.dart'; | ||
|
|
||
| /// Options for [ImagePickerCameraDelegate] methods. | ||
| /// | ||
| /// New options may be added in the future. | ||
| @immutable | ||
| class ImagePickerCameraDelegateOptions { | ||
| /// Creates a new set of options for taking an image or video. | ||
| const ImagePickerCameraDelegateOptions({ | ||
| this.preferredCameraDevice = CameraDevice.rear, | ||
| this.maxVideoDuration, | ||
| }); | ||
|
|
||
| /// The camera device to default to, if available. | ||
cbracken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final CameraDevice preferredCameraDevice; | ||
|
|
||
| /// The maximum duration to allow when recording a video. | ||
cbracken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final Duration? maxVideoDuration; | ||
| } | ||
|
|
||
| /// A delegate for `ImagePickerPlatform` implementations that do not provide | ||
| /// a camera implementation, or that have a default but allow substituting an | ||
| /// alternate implementation. | ||
| abstract class ImagePickerCameraDelegate { | ||
| /// Takes a photo with the given [options] and returns an [XFile] to the | ||
| /// resulting image file. | ||
| /// | ||
| /// Returns null if the photo could not be taken, or the user cancelled. | ||
| Future<XFile?> takePhoto({ | ||
| ImagePickerCameraDelegateOptions options = | ||
| const ImagePickerCameraDelegateOptions(), | ||
| }); | ||
|
|
||
| /// Records a video with the given [options] and returns an [XFile] to the | ||
| /// resulting video file. | ||
| /// | ||
| /// Returns null if the video could not be recorded, or the user cancelled. | ||
| Future<XFile?> takeVideo({ | ||
| ImagePickerCameraDelegateOptions options = | ||
| const ImagePickerCameraDelegateOptions(), | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/image_picker/image_picker_platform_interface/test/image_picker_platform_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:image_picker_platform_interface/image_picker_platform_interface.dart'; | ||
|
|
||
| void main() { | ||
| group('ImagePickerPlatform', () { | ||
| test('supportsImageSource defaults to true for original values', () async { | ||
| final ImagePickerPlatform implementation = FakeImagePickerPlatform(); | ||
|
|
||
| expect(implementation.supportsImageSource(ImageSource.camera), true); | ||
| expect(implementation.supportsImageSource(ImageSource.gallery), true); | ||
| }); | ||
| }); | ||
|
|
||
| group('CameraDelegatingImagePickerPlatform', () { | ||
| test( | ||
| 'supportsImageSource returns false for camera when there is no delegate', | ||
| () async { | ||
| final FakeCameraDelegatingImagePickerPlatform implementation = | ||
| FakeCameraDelegatingImagePickerPlatform(); | ||
|
|
||
| expect(implementation.supportsImageSource(ImageSource.camera), false); | ||
| }); | ||
|
|
||
| test('supportsImageSource returns true for camera when there is a delegate', | ||
| () async { | ||
| final FakeCameraDelegatingImagePickerPlatform implementation = | ||
| FakeCameraDelegatingImagePickerPlatform(); | ||
| implementation.cameraDelegate = FakeCameraDelegate(); | ||
|
|
||
| expect(implementation.supportsImageSource(ImageSource.camera), true); | ||
| }); | ||
|
|
||
| test('getImageFromSource for camera throws if delegate is not set', | ||
| () async { | ||
| final FakeCameraDelegatingImagePickerPlatform implementation = | ||
| FakeCameraDelegatingImagePickerPlatform(); | ||
|
|
||
| expectLater(implementation.getImageFromSource(source: ImageSource.camera), | ||
| throwsStateError); | ||
| }); | ||
|
|
||
| test('getVideo for camera throws if delegate is not set', () async { | ||
| final FakeCameraDelegatingImagePickerPlatform implementation = | ||
| FakeCameraDelegatingImagePickerPlatform(); | ||
|
|
||
| expectLater(implementation.getVideo(source: ImageSource.camera), | ||
| throwsStateError); | ||
| }); | ||
|
|
||
| test('getImageFromSource for camera calls delegate if set', () async { | ||
| const String fakePath = '/tmp/foo'; | ||
| final FakeCameraDelegatingImagePickerPlatform implementation = | ||
| FakeCameraDelegatingImagePickerPlatform(); | ||
| implementation.cameraDelegate = | ||
| FakeCameraDelegate(result: XFile(fakePath)); | ||
|
|
||
| expect( | ||
| (await implementation.getImageFromSource(source: ImageSource.camera))! | ||
| .path, | ||
| fakePath); | ||
| }); | ||
|
|
||
| test('getVideo for camera calls delegate if set', () async { | ||
| const String fakePath = '/tmp/foo'; | ||
| final FakeCameraDelegatingImagePickerPlatform implementation = | ||
| FakeCameraDelegatingImagePickerPlatform(); | ||
| implementation.cameraDelegate = | ||
| FakeCameraDelegate(result: XFile(fakePath)); | ||
|
|
||
| expect((await implementation.getVideo(source: ImageSource.camera))!.path, | ||
| fakePath); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| class FakeImagePickerPlatform extends ImagePickerPlatform {} | ||
|
|
||
| class FakeCameraDelegatingImagePickerPlatform | ||
| extends CameraDelegatingImagePickerPlatform {} | ||
|
|
||
| class FakeCameraDelegate extends ImagePickerCameraDelegate { | ||
| FakeCameraDelegate({this.result}); | ||
|
|
||
| XFile? result; | ||
|
|
||
| @override | ||
| Future<XFile?> takePhoto( | ||
| {ImagePickerCameraDelegateOptions options = | ||
| const ImagePickerCameraDelegateOptions()}) async { | ||
| return result; | ||
| } | ||
|
|
||
| @override | ||
| Future<XFile?> takeVideo( | ||
| {ImagePickerCameraDelegateOptions options = | ||
| const ImagePickerCameraDelegateOptions()}) async { | ||
| return result; | ||
| } | ||
| } |
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.