Use if condition instead of conditional expression
Many times we need to render a widget based on some conditions in Row and Column. If conditional expression return null in any case then we should use if condition only.
Do
Widget getText(BuildContext context) {
return Row(
children: [
Text("Hello"),
if (Platform.isAndroid) Text("Android")
]
);
}
Don't
Widget getText(BuildContext context) {
return Row(
children: [
Text("Hello"),
Platform.isAndroid ? Text("Android") : null,
Platform.isAndroid ? Text("Android") : SizeBox(),
Platform.isAndroid ? Text("Android") : Container(),
]
);
}