Skip to content

Conditionals inside nested expressions #70

Closed
@mit-mit

Description

@mit-mit

Flutter code contains UI descriptions that are naturally ordered, with a set of arguments typically specified in the rough order they appear on the screen, e.g.:

  Widget buildBody() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Text('Text 1'),
        Text('Text 2'),
        Text('Text 3'),
      ],
    );
  }

However, when some of these elements need to be conditionally shown, the developer is forced to restructure the method "backwards"; with the conditional code first, and then the code for what surrounds the conditional code:

  Widget buildBody() {
    List<Widget> children;
    children.add(Text('Text 1'));
    if (someCondition == true) {
      children.add(Text('Text 2'));
    }
    children.add(Text('Text 3'));

    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: children,
    );
  }

The present issue requests support for some way of writing conditional code "as part of the statements".

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions