I want to use if condition in the icon widget, but Dart gives an error. How should it be used correctly? Thanks.
class Cell extends StatelessWidget {
const Cell({super.key, this.caseTrend = false});
final bool caseTrend;
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("23.410"),
Icon(
if(caseTrend) {
Icons.trending_up,
color: Colors.green,
}
else
{
Icons.trending_down,
color: Colors.red,
},
size: 24,
)
],
),
);
}
}
What I have tried:
class Cell extends StatelessWidget {
const Cell({super.key, this.caseTrend = false});
final bool caseTrend;
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Text("23.410"),
Icon(
caseTrend ? Icons.trending_up : Icons.trending_down,
color: caseTrend ? Colors.green : Colors.red,
size: 24,
)
],
),
);
}
}