-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Do not require main asset files if variants are provided #10901
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
Conversation
|
You might also need to update dartdocs in various places, comments in the pubspec.yaml.tmpl file, and various things on our Web site. |
|
I have updated the pubspec.yaml file and will have to update the web site (https://flutter.io/assets-and-images/.) separately. |
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.
printError('$e'); is probably more idiomatic. Hopefully it isn't slower. :-)
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.
Is this an invariant at this point, or is this the place where you're checking that the input is valid?
Asserts won't always run in flutter_tools, since we sometimes run it in release mode.
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.
If this is just an invariant that you're checking, leave a comment pointing to where we do the input validation.
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.
The original version of this check had been an invariant but it probably should throw an error. With a mighty helpful error message :-).
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.
variantsFor takes a single string, but you're passing two here, did you mean 'assets/foo'?
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.
Oops, yes. I'd forgotten to update the doc.
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.
This is O(N*M), could _excluded be a Set somehow? I guess the right data structure here is a prefix tree, but that may be going off into the weeds a bit prematurely.
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.
I can just substitute an ordinary loop over the file system entities that builds the list of paths.
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.
Writing a loop here saves the cost of creating a list of paths and then a copy of that after filtering out the excluded paths. The excluded list is length 2, I think that's probably enough tweaking.
|
LGTM (mostly... a bit RSLGTM, @tvolkert may be a better reviewer). The only suggestion I would have is to add an end-to-end test (in the devicelab) that verifies that this works (i.e. that if you only have 2x and 3x variants, on a 1x device, you get the 2x variant). |
This assumes that flutter/flutter#10901 will land.
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.
assetVariants can't be empty, since we're iterating through it.
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.
Good catch, that was supposed to be assetVariants[asset].isEmpty
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.
... which makes this if check redundant
766cf9e to
5733386
Compare
This assumes that flutter/flutter#10901 will land.
If variants are found for an asset then we don't require that the "main" asset's file exists.
Replaced the N-squared algorithm that matches assets and variants; now it's O(N).
Fixes #8231