dart-lang / dart-lang/language
[Feature] Add support for an Undefined data type
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Since we have this type in other languages, it would be nice to have it in Dart. It'll greatly strengthen the usefulness of `copyWith` functions, so that `null` values can be differentiated from values that have not been defined.
Use case:
```dart
class MapState1 {
MapState copyWith({
Category activeTopCategory,
Category activeCategory,
}) {
return MapState(
activeTopCategory: activeTopCategory ?? this.activeTopCategory,
activeCategory: activeCategory ?? this.activeCategory,
);
}
```
If I decide to set the `activeCategory` to null, the newly created object will have the same values as the old object. I cannot figure out a reasonable workaround for this.
The second use-case is more common in widgets with optional named parameters with default values. If someone passes in that value using a variable and that variable turns out to be null, we don't get the default value, and there's no way to pass in a value sometimes and leave it undefined at others without creating 2 separate widgets.
Contributor guide
Assessment
This issue has not been assessed yet.