I tried to add the text as below to make it work but it just shows =(sum of round 1) +(sum of round 2) but doesnt add them up: CODE
Text(
"Result n Round 1: $roundOneResult and Round 2: $roundTwoResult Total = $roundOneResult + $roundTwoResult",
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 30,
),
),
],
),
),
);
}
}
I tried the above and was expectingenter image description here
more code sample if you need a reference thanks all:
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text("Add"),
onPressed: () {
setState(() {
roundOneFields.forEach((e) =>
roundOneResult = roundOneResult + int.parse(e.text));
roundTwoFields.forEach((e) => roundTwoResult =
roundTwoResult + int.parse(e.text.toString()));
});
},
)
],
),
Text(
"Result n Round 1: $roundOneResult and Round 2: $roundTwoResult Total = $roundOneResult + $roundTwoResult",
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 30,
),
),
],
),
),
);
}
}
2
Answers
this problem arose because you added val 1 and val 2 with ‘+’ which is working as a String. try this:
if. it’s worked then mark it as solved.
The other answer is also correct. Anotherway,