rafidgotit / media_picker_widget

A widget that picks media files from storage and allows you to place anywhere in the widget tree.
MIT License
13 stars 14 forks source link

Ensure onPicked only calls if completeSelection been called. #10

Closed laeo closed 11 months ago

laeo commented 11 months ago

Many thanks to your work, but i'v found the code below

void updateSelection(List<MediaViewModel> selectedMediaList) {
    if (widget.mediaCount == MediaCount.multiple) {
      setState(() {
        _selectedMedia = selectedMediaList;
      });
    } else if (selectedMediaList.length == 1) {
      widget.onDone(selectedMediaList);
    }
  }

When user selected a photo, it will auto call onPicked callback, its weird, user should to confirm their choice.

Can you update the logic to ensure the onPicked callback only calls if completeSelection called.

rafidgotit commented 11 months ago

Many thanks to your work, but i'v found the code below

void updateSelection(List<MediaViewModel> selectedMediaList) {
    if (widget.mediaCount == MediaCount.multiple) {
      setState(() {
        _selectedMedia = selectedMediaList;
      });
    } else if (selectedMediaList.length == 1) {
      widget.onDone(selectedMediaList);
    }
  }

When user selected a photo, it will auto call onPicked callback, its weird, user should to confirm their choice.

Can you update the logic to ensure the onPicked callback only calls if completeSelection called.

@laeo , Thank you so much for the appreciation. Please let me be clear about the issue. Are you talking about single selection mode? Usually users just select the picture and it's done. Maybe you have a requirement where user can change the mode from single to multiple. I would like to ask isn't multiple picking mode solving your issue?

laeo commented 11 months ago

Many thanks to your work, but i'v found the code below

void updateSelection(List<MediaViewModel> selectedMediaList) {
    if (widget.mediaCount == MediaCount.multiple) {
      setState(() {
        _selectedMedia = selectedMediaList;
      });
    } else if (selectedMediaList.length == 1) {
      widget.onDone(selectedMediaList);
    }
  }

When user selected a photo, it will auto call onPicked callback, its weird, user should to confirm their choice. Can you update the logic to ensure the onPicked callback only calls if completeSelection called.

@laeo , Thank you so much for the appreciation. Please let me be clear about the issue. Are you talking about single selection mode? Usually users just select the picture and it's done. Maybe you have a requirement where user can change the mode from single to multiple. I would like to ask isn't multiple picking mode solving your issue?

Yes, i'm talking about single selection mode.

I think it may better to use completeSelection callback to control when the selection is done. Force call onDone() when user just selected a photo is not a good idea.

Maybe provide completeSelection to onPicking() callback is more better way.

MediaPicker(
  onPicking: (List<Media> selected, VoidCallback completeSelection) {
    if (selected.length == 1) completeSelection();
  },
);