Mark IconData final and @mustBeConst#18134
8000
5
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
This pull request makes IconData a final class and adds @mustBeConst to its constructor parameters, which is a great improvement for enforcing immutability and enabling compiler optimizations. My review includes a suggestion to apply the @mustBeConst annotation to all constructor parameters for completeness and consistency.
|
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visit Writing a golden file test for Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
There was a problem hiding this comment.
Seems like a win to me. I want to be sure that Material and Cupertino don't have any breaking usages of IconData though (doesn't look like it to me if I grep through the codebase).
I haven't worked on the rfw codebase, but taking a look it seems like it won't be possible for it to support icon tree shaking. That makes sense for a package that can execute code at runtime that is unknown at compile time, so I expect users of rfw will understand.
|
FYI, some folks use the
This comment explains why folks use this pattern: #126261 (comment)
However, it seems that this improvement is nice enough to warrant breaking breaking this pattern. |
@Albert221 You rely on subtyping |
|
@dcharkes Hey! That is correct, they're not tree-shaken at all if I use Setup we use for many projects and that many clients use in their codebases usually is:
|
|
Thanks for the reply @Albert221 🙏 Okay, then the tree-shaking is WAI in your use case. I suppose asking you to migrate away from |
|
Not ideal but possible, yes. If that's for the sake of making Flutter better for everyone, go for it |
🙏 👍 ! Okay, when we do this as a breaking change, then older versions of WidgetBook will stop working in a newer Flutter version. Please let me know when you have migrated, and if the migration didn't caused breaking change issues on your side (looking at the code I don't think so, but I might be wrong). I'll wait with landing anything on master for a while (and need to file a breaking change announcement as well) to ensure no one breaks. |
6c1c25c to
63b8163
Compare
We are introducing the `@mustBeConst` annotation on `IconData` parameters that must be const in order for the icon tree shaker to work: * flutter/flutter#181344 * flutter/flutter#181345 RFW does not support tree-shaking. This PR adds the lint ignores with an explicit comment that the lint ignore is intentional.
63b8163 to
84a1207
Compare
Proof of concept for:
class IconDataasfinal#181342IconData's constructor parameters as@mustBeConst#181344See the issue descriptions for the motivation.
cc @Piinks
It seems we have a non-const use in the Remote Flutter Widgets:
https://github.com/flutter/packages/blob/d0c7d1fad77331724882614345137221c77d5758/packages/rfw/lib/src/flutter/argument_decoders.dart#L801-L811
The package itself makes no mention of it not work with the Flutter Icon Tree Shaker. If it's a know issue that the icon tree shaker is not supported with
package:rfwwe can add// ignore: non_const_argument_for_const_parameter. (flutter/packages#10858)2026-03-10 update, no push-back on the breaking changes. Migrations done / in progress downstream:
IconDatabeing markedfinalfluttercommunity/font_awesome_flutter#297IconDataasfinalFaFre/WebLibre#214