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

updating example and adding method #366

Closed
wants to merge 11 commits into from

Conversation

rodydavis
Copy link

  • Adding pickMedia()
  • Updated Example
  • Fixing some typos
/// Returns a [PickedFile] with the image that was picked.
  ///
  /// The `source` argument controls where the image comes from. This can
  /// be either [ImageSource.camera] or [ImageSource.gallery].
  /// 
  /// The `type` argument controls what the content return type. This can
  /// be either [RetrieveType.image] or [RetrieveType.video].
  ///
  /// If specified, the image will be at most `imageMaxWidth` wide and
  /// `imageMaxHeight` tall. Otherwise the image will be returned at it's
  /// original width and height.
  ///
  /// The `imageQuality` argument modifies the quality of the image, ranging from 0-100
  /// where 100 is the original/max quality. If `imageQuality` is null, the image with
  /// the original quality will be returned. Compression is only supported for certain
  /// image types such as JPEG. If compression is not supported for the image that is picked,
  /// an warning message will be logged.
  /// 
  /// The [videoMaxDuration] argument specifies the maximum duration of the captured video. If no [videoMaxDuration] is specified,
  /// the maximum duration will be infinite.
  ///
  /// Use `preferredCameraDevice` to specify the camera to use when the `source` is [ImageSource.camera].
  /// The `preferredCameraDevice` is ignored when `source` is [ImageSource.gallery]. It is also ignored if the chosen camera is not supported on the device.
  /// Defaults to [CameraDevice.rear].
  ///
  /// 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> pickMedia({
    @required ImageSource source,
    @required RetrieveType type,
    double imageMaxWidth,
    double imageMaxHeight,
    int imageQuality,
    Duration videoMaxDuration,
    CameraDevice preferredCameraDevice = CameraDevice.rear,
  }) {
    throw UnimplementedError('pickMedia() has not been implemented.');
  }

Copy link
Owner

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rody, this looks to me like a new feature for the release after enabling web with the "new" API. Are you in the future already? :P :P Can we release this after the current big PR goes through?

If you have specific changes about the current PR, I'd be glad to merge them, but in this case, the new pickMedia API looks a bit premature, doesn't it?

@@ -40,7 +40,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
PickedFile _imageFile;
dynamic _pickImageError;
bool isVideo = false;
RetrieveType mediaSource = RetrieveType.video;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this mediaType to not confuse it with the current source (gallery vs camera)

});
}
});
switch (mediaSource) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of this global controlling the behavior of this method.

Do you think it'd be possible to split _onImageButtonPressed in two methods: _onImageButtonPressed and _onVideoButtonPressed? (Also I've seen other parts of the code using this global-but-not-quite-part-of-the-state variable)

(Anyway, that might be a refactor for another time)

Comment on lines +199 to +205
@required ImageSource source,
@required RetrieveType type,
double imageMaxWidth,
double imageMaxHeight,
int imageQuality,
Duration videoMaxDuration,
CameraDevice preferredCameraDevice = CameraDevice.rear,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change, but I'd prefer to add this after the web version is in, to not add a new platform + new functionality. Can we do this in a follow up to the current change?

About the functionality itself, this seems to be a big fusion of all the pick* methods that are currently implemented. If "pickAudio" or "pickFile" get added, this method will grow in complexity (it'll probably need more parameters).

Maybe the best way to go is to have a completely agnostic "pickFile" method that lets you select anything from the disk.

That API can have the RetrieveType parameter if we want to limit to some types, but it wouldn't concern itself with "imageQuality" or "videoDuration".

That would be a much simpler API, if you needed to pick from multiple types IMO!

Duration videoMaxDuration,
CameraDevice preferredCameraDevice = CameraDevice.rear,
}) {
switch (type) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid these switches on Enum IMO, because when you add a new value to the Enum, you break whoever was switching on it, if they don't have a default case.

There should always be a default case (or possibly better, not switch on Enums :P)

@rodydavis
Copy link
Author

Oh for sure! Yeah I was just making it to show you what I was thinking. PR is fine as it is 👍🏼

@ditman
Copy link
Owner

ditman commented May 19, 2020

@rodydavis let's revisit this, after the web version gets merged. What do you think about having a less specific pickFile instead of an "union" method to Rule Them All?

I'm sure this was inspired by your own use cases of the picker in the past, I'm very curious! (We can discuss via email if you prefer)

@rodydavis
Copy link
Author

Yeah I like the idea of it being less specific for sure. For many apps though I need to rebuild the logic for picking a photo, image or file and they all usually are under a onpressed event and return a file. Having a pickFile would be great to add. And then if it is filtered to just photos or videos it would choose appropriately.

Side note, are there plans to support saving image, photos and videos too? That’s a bother thing I’m heavily replicating, but could also be another plugin

@ditman
Copy link
Owner

ditman commented May 19, 2020

I think saving needs to be a separate plugin. It's super transparent for the mobile use case, but it's not so clear in the Browser. (I'm concerned with initializing the file in a way that makes sense with the mobile code :/)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants