dart-lang / dart-lang/language

Conditionally omitted arguments

Open
#62 15 comments 1 reaction 0 assignees View on GitHub
request
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

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.