flutter / flutter/flutter-intellij

Proposal: Offer a "copy with" generate option

Open
#4,878 3 comments 29 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
356
Avg merge
1d 11h
Merged PRs (30d)
27

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`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.