dart-lang / dart-lang/language
Conditionally omitted arguments
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Not sure if 'conditional statements' is the right terminology but frequent issues while using Dart as UI are as follows:
```dart
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: ListView(
children: [
PageHeader(),
isSignedIn ? SignInButton : justDon'tDoAnything
RestOfThePage()
],
),
);
}
```
In the case above, we don't actually want to return null since null has a different semantic meaning as one of the list elements.
There are of course imperfect work-arounds such as appending `..where((Widget item) => item != null)` or returning `: SomeFlutterWidgetThatDoesn'tDoAnythingInTheListView` but they're still impedances to Dart as UI.
Another example is
```dart
WidgetA( // <= constructor
paramA: overrideValueA,
paramB: ifIShouldOverride ? overrideValueB : justDon'tDoAnythingAndLeaveConstructorDefaultWhichMayBeDifferentFromNull
)
```
Again, the present workaround solution is to wrap the whole constructor and invoke it differently twice, but it would be great if this can be expressed succinctly in the spirit of #47
Contributor guide
Assessment
This issue has not been assessed yet.