Open matthew-carroll opened 4 years ago
Do these methods typically exist on Flutter framework classes? Objects used by the framework? Widget classes?
I want to make sure that we don't over-offer this option - that we don't offer it for every type of class, if that ends up being too noisy.
It makes sense for any immutable data structure, e.g., ThemeData
. I'm not sure how one would differentiate a class it applies to and a class it doesn't apply to, but that's the target.
Many people use code generation for this kind of stuff. Freezed package is probably the most popular one. Just an FYI using code generation can "break" the Dart analyzer so it will show old errors instead of correct ones. Here is an issue regarding the problem https://github.com/dart-lang/sdk/issues/43166
Also if this comes supported, then fromJson and toJson methods should be implemented as well.
Pressing
ctl+enter
in Android Studio brings up a menu with auto-generation options. This is often used to generate==
andhashCode
methods.In Flutter there is often a need for a
copyWith
method, which is used to duplicate an existing data structure with some number of alterations. For example:A
copyWith
method might look like:I think it would be a good idea to add a generation option for a
copyWith
method, with a generator that would look and operate almost identically to that of==
andhashCode
.