Reputation: 7166
In flutter_lints
the use_key_in_widget_constructors
lint requres providing a key when creating public widgets.
It's a good practice to expose the ability to provide a key when creating public widgets.
class MyPublicWidget extends StatelessWidget {
MyPublicWidget({Key? key}) : super(key: key);
}
What is actualy the purpose of this lint rule i.e. what it gives?
Upvotes: 4
Views: 661
Reputation: 290
As this article states:
Upvotes: 3
Reputation: 277077
This is a convention. All widgets should allow specifying a key.
Your app won't suddenly stop working if a widget doesn't, but respecting that convention is a good thing.
It'd be inconvenient for users of a widget if they need to specify a key but that widget doesn't allow them to.
Upvotes: 3