flutter_file_picker
flutter_file_picker copied to clipboard
Files number limit
Is that possible to determine the number of files the user can select? for example, I do not want to let the user select more than 5 files.
Hi! This has been requested multiple times (see #314, #118, #365, #64, #353). But never implemented only because on Android it might not be honoured and would mislead some users or developers.
On iOS though this can be easily achieved.
I might add it with a disclaimer warning regarding this as it should work most of the times.
Just for later reference, Android doesn't support this feature at all as referenced on the docs. This means that either the user has the ability to pick multiple files or not.
Because of this and since the feature is possible to implement on iOS, I will probably discard any N+ allowed items and display a toast with that info so the user knows it reached maximum file picks and all the N+ files were discarded because of that.
I think it will help all developers using your dependency. Thank you for following up. 👍👍
I think it is the most important future for allow multi-select.
I want to know your input about my findings regarding this:
Android
- It's impossible to limit or ensure the file limits other than discarding the N+ picked items (on my side) which may result in a oddly user experience, nevertheless, this would be always optional so it would be up to the devs to decide;
iOS
- Currently, using
FileType.all
opens Files app (which is expected). Bottom line is that isn't impossible to limit file selection here, so it would have to act the same way as Android (discarding N+ items). - It's completely possible to limit the selection from gallery picking (media files). So that's a plus.
Web
- I'm not sure if this is possible at all. If not, the same approach of Android is always possible;
With all of that said, I'm still reticent about having this feature, since it may result in significant new issues as devs may find the experience somewhat unpleasant. What's your thoughts?
Thanks!
@miguelpruivo Thank you for your reply. In my situation, I using flutter for android and ios, that's why I'm not concerned about the web. I using React on the web.
I think the limit file is a common feature when the user selects a file. You can see many popular apps also provide that.
If you think this feature will make someone confuse, because some cases may not work. I think you can create a new method, like pickLimitFiles, and mark which case it does not work.
Thanks!
@miguelpruivo could be possible to have it for iOS? I think we can have a validation for the number of files in Android to double check the user didn't select more but we could have this UX improved with iOS at least
@erperejildo on iOS this is easily doable on media picks, however, Files app picks doesn’t provide a way to limit selection as well.
I’m afraid that it may introduce a lot of misusage for developers if the feature is only implemented for some particular types.
For example, picking paths isn’t supported on the web, and despite having documented it and throwing an error when accessing path property on Flutter Web, there are still people every now and then opening issues because “it doesn’t work”.
I want to keep it as simple as possible without having devs confused about whether a particular feature will work on all devices or not, but haven’t come with a clean solution yet — plus, working on this only on my free time, which lately hasn’t been much. 😔
In that case to avoid more questions about this, I'd add this info to the docs
They could do it on Android: https://github.com/sangcomz/FishBun
@kreativityapps that’s by using a 3rd party picker. Not natively, unfortunately.
@miguelpruivo any good news?
Just for later reference, Android doesn't support this feature at all as referenced on the docs. This means that either the user has the ability to pick multiple files or not.
Because of this and since the feature is possible to implement on iOS, I will probably discard any N+ allowed items and display a toast with that info so the user knows it reached maximum file picks and all the N+ files were discarded because of that.
I wonder if this might be a good place for a custom builder option? Let the dev have a way to build said message?
I know it could be done already but it would be convenient to have a builder option that is automatically called if/when the single file picker is used.
You could also make it a different init function. Like
FilePicker.platform.pickFile
And make the message required to init the single pick mode. That way it draws attention to the dev about what is happening / they can't get a new instance without providing the message for Android.
@miguelpruivo I'm curious what your thoughts are on my proposed solution? Thanks for your time.
@kenthinson well, I've started this a couple of times but I believe there is not "clean" way to do so other than creating a custom picker — which I don't want to. I follow the native platform pickers along with their own capabilities, that's one of the main features of this plugin. However, the only way I can see this being done across all platforms is by discarding and showing an error after picking the N+ files, however, this can be easily done when needed by the dev, hence, I still don't have a clue whether or not this should be implemented.
I'm open to any ideas.
Any updates on this ?
Hi, unfortunately no. I don’t believe there is a easy way to do this natively.
Hi, How the WhatsApp restrict the max of 30 files, how we use this restriction and max of 5.
@miguelpruivo from what I understand there is a newer Android Photo Picker API that let you set a max items limit.
Maybe you can add this only for media/photos/video options.
Any update on this feature?
This is a high priority feature, but I don't have any ETA since I haven't much time to work on this. Any help would be appreciated. ♥️
Looking forward to this feature🥹