ifTrue method

dynamic ifTrue(
  1. dynamic yes, [
  2. dynamic no
])

Return yes if the boolean is true, otherwise return no

When no is not specified, it will return null or return SizedBox if yes is a Widget

Example usage:

Widget buildText(BuildContext context, bool shouldGreet) {
  return shouldGreet.ifTrue(
    Text("Hello"),
  );
}

Implementation

ifTrue(yes, [no]) {
  if (yes is Widget && this == false) {
    return no ?? SizedBox();
  }
  return this ? yes : no;
}