While working on a recent project of mine, I wanted to display an image conditionally. And it turned out you could do it in flutter.

Here’s how:

  1. type an inline if statement
  2. add a new line for the widget
  3. profit
Widget build(BuildContext context) => Column(
	color: Colors.red,
	children: <Widget>[
		if(true)
			Text("conditional text"),
		Text("hello"),
	],
);

Bonus

Conditional attribute using one line if statement.

Widget build(BuildContext build) => Container(
	color: true ? Colors.red : null
);

Which goes as follows

condition ? what happens if true : what happens if false