Quantcast
Channel: Dart: spread operator for constructor - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Dart: spread operator for constructor

$
0
0

In my flutter app, I have widgets like below:

Container(  decoration: BoxDecoration(    border: Border.all(      color: Colors.red,      width: 2,      style: BorderStyle.solid,    ),  ),  child: Text('Container 1'),)
Container(  decoration: BoxDecoration(    border: Border(      top: BorderSide(        color: Colors.red,        width: 2,        style: BorderStyle.solid,      ),    ),  ),  child: Text('Container 2'),)

Both use the same properties for their borders. So I was wondering if there's a spread-operator-like way of inserting the same properties for both widgets? Maybe like:

const borderBase = (  color: Colors.red,  width: 2,  style: BorderStyle.solid,)Container(  decoration: BoxDecoration(    border: Border.all(      ...borderBase,    ),  ),  child: Text('Container 1'),)Container(  decoration: BoxDecoration(    border: Border(      top: BorderSide(        ...borderBase,      ),    ),  ),  child: Text('Container 2'),)

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images