Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter conditional statement with Card(color:)

I am trying to change the color below from red to green if the value of a variable is more than 10. How would I do that? as 'color:' does not accept if, else statements:

         Card( 
            child: Column(
              children:[
                Text('Calls Taken',
                style: TextStyle(
                  fontSize: 16.0,
                  decoration: TextDecoration.underline,
                ),),
                Text('10'),
              ],
            ),
            color: Colors.redAccent

          ),

The above card widget is under a class that inherits StatelfulWidgets

Thank you in advance!!!

like image 953
p479 Avatar asked Mar 11 '19 11:03

p479


1 Answers

Just use a ternary if

color: variable > 10 ? Colors.redAccent : Colors.green
like image 126
Günter Zöchbauer Avatar answered Sep 21 '22 22:09

Günter Zöchbauer