Spread operators

Spread operators

Dart 2.3 Introduced very useful features and one of them I like is Spread operators. It allows us to write UI as Code meaning, with spread operator you can write if-else statement while writing the widget. For example

Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (age >= 18) ...[adultView(true)] else adultView(false),
],
)

This could also be written as

Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
age >= 18 ? adultView(true) : adultView(false),
],
)

But Spread operators are very useful when you have nested if-else condition.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

How to extract filename from Uri?

Now, we can extract filename with and without extension :) You will convert your bitmap to uri and get the real path of your file. Now w...