Write Cleaner Code Using the Spread Operator Tips - 3

In this article I will share with you write cleaner code tip.

The Dart 2.3 introduced a few useful features and one of them I like is the Spread operator. This is very useful when you need conditional UI widgets. Specially when you have nested conditional UI Widget.

Stack(
     alignment: Alignment.center,
     children: <Widget>[
     if (_visible) ...[
          spaceAnim(),
          //Nested if-else
          if (_visible) ...[
              spaceAnim(),
          ]else ...[
              galaxyAnim(),
           ],
     ]else ...[
         galaxyAnim(),
     ],
  ],
),

 

Tags: