Skip to content

Conditionals inside nested expressions #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mit-mit opened this issue Oct 31, 2018 · 4 comments
Closed

Conditionals inside nested expressions #70

mit-mit opened this issue Oct 31, 2018 · 4 comments
Labels
request Requests to resolve a particular developer problem

Comments

@mit-mit
Copy link
Member

mit-mit commented Oct 31, 2018

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

@mit-mit mit-mit added the request Requests to resolve a particular developer problem label Oct 31, 2018
@mdebbar
Copy link

mdebbar commented Nov 1, 2018

@mit-mit you might find the ui-as-code project interesting. It covers several issues like this one. See https://github.com/munificent/ui-as-code/blob/master/Motivation.md#p1-conditionally-omitting-content.

cc @munificent

@mit-mit
Copy link
Member Author

mit-mit commented Nov 1, 2018

Yes, I'm very aware of that effort. This issue more formally tracks one of the parts from it.

@munificent
Copy link
Member

Do we need both this issue and #62? They seem like duplicates.

@munificent
Copy link
Member

I guess we can close this now that we have collection-if. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Requests to resolve a particular developer problem
Projects
None yet
Development

No branches or pull requests

3 participants