Explore IconData being marked final#297
Conversation
|
@michaelspiss I have played around a bit with the first option from flutter/flutter#181342 (comment) (as the second option is only an option after we release the new technology which allows packages to tree-shake their own assets). If I understand it correctly, the correct use was to use But the tests of users require a breaking change for users to access the This PR makes the typing stricter, so non font-awesome icons can no longer be used with icon data that is not font-awesome, and font-awesome icon data can no longer be used with a non font-awesome icon. I the first one would have worked properly before, but the latter one would have caused issues with the non-square icons. So the latter one is hopefully an improvement. I am not very familiar with how your package is being used. So maybe this PR doesn't work at all. Please enlighten me if this is the case, and we'll go back to the drawing board! |
|
Friendly ping @michaelspiss |
|
Hey @dcharkes - sorry for the delays, I am currently very limited with the time I am able to spend on OSS. I'll try to come back to you faster so you can proceed. Your PR certainly looks like it would work in our context. Especially the package's icons only working with FaIcon is a welcome improvement as it completely eliminates this pitfall. It's good to see that the main user code stays completely untouched and the breaking change for tests is more than reasonable only being a single |
Thanks @michaelspiss! 🙏
Yes, if Flutter addresses that issue, then the desired pattern would be the one in flutter/website#13005 instead. You use your own custom wrapper class where you nest static consts, but the static const instances would be If that happens in the future, the tests would have to be migrated back again. (And you'd probably mark
Great! What is your preferred way of moving forward? Do you want to review this PR and land it? Or would you prefer incorporating the breaking change in a different way on this repo before I make the breaking changes upstream in Flutter? |
|
Thanks for the input! Your PR already looks great - I'd look over it once again in a review and publish it by the end of the week |
|
Hey @dcharkes! Fyi, I just released version 11 with your changes |
|
Thanks for the help, much appreciated! |
You're welcome! |
PR Description: Migration to
FaIconDataWrapperSummary
This PR transitions the
font_awesome_flutterpackage from an inheritance-based icon model to a composition-based "Wrapper" model. This change is necessitated by the upcoming Flutter framework change whereIconDatais marked asfinal(flutter/flutter#181342).By introducing
FaIconData, we also solve a long-standing issue where users would accidentally use Font Awesome icons with the standard FlutterIconwidget, leading to incorrect rendering of rectangular icons.Breaking Changes
FontAwesomeIconsnow returnFaIconDatainstead ofIconData.FaIconDatano longer implements or extendsIconData.FaIconwidget now strictly requiresFaIconData. It can no longer be used with standardIconData(e.g.,Icons.add), and the standardIconwidget can no longer be used with Font Awesome icons.find.byIconandfind.widgetWithIconlook at theIcon.iconproperty. SinceFaIconpasses the underlying data to the framework, tests must be updated to match against the raw data:find.byIcon(FontAwesomeIcons.gamepad.data).Technical Details
FaIconDataWrapper: A new@immutable final classthat wraps a standardIconDatainstance.FaIconRefactor:FaIconData? _icon.super(null)in the constructor to allow forconstinitialization while avoiding invalid property access on parameters.IconData? get icon => _icon?.datato remain compatible with the Flutter framework's layout and testing machinery.util/lib/main.dartto generate icons using the new wrapper and updated Font Awesome to version 7.2.0.Migration Guide
In Widgets
Before:
After:
In Tests
Before:
After:
Versioning
11.0.0-wipto reflect these significant breaking changes.