-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[file_selector] Throw for unsupported type groups #6120
[file_selector] Throw for unsupported type groups #6120
Conversation
Updates all implementations to use the new `allowAny` to identify wildcard groups, and to throw an `ArgumentError` for any group that is not a wildcard, but doesn't set at least one of the filter types supported by the current platform. This is a breaking change to each implementation package. A follow-up will make a breaking change to the app-facing package to pick up these changes and to document the new behavior. Part of flutter/flutter#107469
|
Once this lands I'll update the FDE Linux implementation. |
|
QQ about this. Since users can pass an array of type groups in general, and we treat those as an OR (because a wildcard short-circuits the whole thing), why interrupt the processing of type groups because one of them seems wrong? Shouldn't the check happen at the end, when after looking at all the type groups we cannot find anything compatible with the platform (and the user didn't pass a wildcard?). Additionally we can Failing on the first "wrong" group looks like it's breaking the normal short-circuiting of the OR operator. Imagine this: Do we want the above to fail (because SomeRandomConfig is not supported in the current platform), or apply a Wildcard? The reverse wouldn't fail, because the Wildcard would supersede the random config (and the user wouldn't be aware of it): |
This varies by platform, actually. The reason it's an array of groups that are themselves a bunch of arrays, rather than one group, is that on Windows and Linux each group is one entry in a drop-down list in the dialog. So there's no short-circuiting on those platforms; the overall capability of the dialog is an OR, but each group is distinct. We could be more lenient on some platforms, but my thought was that it's probably not really useful to go out of our way to accept invalid groups in some cases on some platforms. We could also be more strict and always check everything, but that also seemed to me to be more trouble than it's worth; if you think the consistency is important this would be my preference so that we're also consistent with the platforms where we always use everything. My goal was just to make sure that in any case where we would do the wrong thing we throw instead of silently being wrong, and used the simplest implementation that did that. I agree the behavior varying by order is a bit weird if we compare different invalid cases; how do you feel about validating everything instead of explicitly ignoring invalid groups in cases where they don't actually apply? |
|
Ah, I remember now the Windows and Linux use cases!
Yeah, this is a very good point.
Haha, nope, I think I prefer having more leniency with the users, rather than being more strict in this :P
I mean, we can be lenient and not completely silent! Something like:
In any case, the approach I described above would be as backwards incompatible as the current version, so there's nothing stopping us from changing this to be more lenient (or more strict) down the line; users' code should expect "throwy" methods from this point on. Also, I suspect people are creating XFileGroups statically somewhere and hiding them from sight, so it's likely that once they get it right it never gets touched again (or only when they want to support a new platform!) Let's land this one! |
ditman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we modify the core package, I think we should be more explicit than "the methods that accept XTypeGroups", and instead list them all, something like:
The following methods: openFile, openFiles and getSavePath may now throw an ArgumentError if the list of XTypeGroups contains a XTypeGroup that doesn't contain appropriate filters for the current platform.
(Or something like that :P)
Co-authored-by: David Iglesias <[email protected]>
Co-authored-by: David Iglesias <[email protected]>
Co-authored-by: David Iglesias <[email protected]>
Updates all implementations to use the new
allowAnyto identifywildcard groups, and to throw an
ArgumentErrorfor any group that isnot a wildcard, but doesn't set at least one of the filter types
supported by the current platform.
This is a breaking change to each implementation package. A follow-up
will make a breaking change to the app-facing package to pick up these
changes and to document the new behavior.
Part of flutter/flutter#107469
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).