Open
Description
Pressing ctl+enter
in Android Studio brings up a menu with auto-generation options. This is often used to generate ==
and hashCode
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:
myTheme.copyWith(
brightness: Brightness.dark,
primaryColor: Colors.yellow,
);
A copyWith
method might look like:
class MyThing {
const MyThing({
this.itemA,
this.itemB,
this.itemC,
});
final String itemA;
final int itemB;
final bool itemC;
MyThing copyWith({
String thingA,
int thingB,
bool thingC,
}) {
return MyThing(
thingA: thingA ?? this.thingA,
thingB: thingB ?? this.thingB,
thingC: thingC ?? this.thingC,
);
}
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 ==
and hashCode
.