I've tried all sorts of things , there isn't seem to be an error in my code . I've also checked the flutter doctor , still I didn't get any results. Can anyone help me, I am a beginner at coding. I guess my set state class has some issue but nothing shows in my terminal window . Please help I'm stuck with this problem and I didn't find anything on google that could answer my question.
Here is my code
class InputPage extends StatefulWidget {
@override
InputPageState createState() => InputPageState();
}
class InputPageState extends State<InputPage> {
Color maleCardColor = inactiveCardColor;
Color femaleCardColor = inactiveCardColor;
void updateColor ( int gender) {
// male was pressed
if (gender == 1) {
if (maleCardColor == inactiveCardColor) {
maleCardColor = activeCardColor;
} else {
maleCardColor = inactiveCardColor;
}
}
if (gender == 2) {
if (femaleCardColor == inactiveCardColor) {
femaleCardColor = activeCardColor;
} else {
femaleCardColor = inactiveCardColor;
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF10A0E21),
appBar: AppBar(
title: Text("BMI CALCULATOR",
),
backgroundColor: Colors.black,
centerTitle: true,
),
body: Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
updateColor(1);
});
},
child: ReusableCard(
cardColor:inactiveCardColor,
cardChild: IconContent(
iconImage: FontAwesomeIcons.mars,
iconText: "MALE",) ,
),
),
),
Expanded(
child:GestureDetector(
onTap: (){
setState(() {
updateColor(2);
});
},
child:ReusableCard(cardColor:inactiveCardColor,
cardChild:
IconContent(iconImage:FontAwesomeIcons.venus,
iconText: "FEMALE",),
),
),`enter code here`
),
],
),
),
Use setState to chagne the state
if (gender == 2) {
if (femaleCardColor == inactiveCardColor) {
setState((){
femaleCardColor = activeCardColor;
});
} else {
setState((){
femaleCardColor = inactiveCardColor;
});
}
}
And also remove setState from here
setState(() {
updateColor(2);
});