'Type 'String' is not a subtype of type 'int' in type cast
Here's the variable I took
int _bmi = 0;
And this is where I used typecast
actions: [
TextButton(
child: const Text('Approve'),
onPressed: () {
setState(() {
int sum = int.parse(massNumber.text) + int.parse(heightNumber.text);
_bmi = sum.toString() as int;
});
},
),
]
On running the program, I'm getting an error:
type 'String' is not a subtype of type 'int' in typecast
Solution 1:[1]
Actually, what you intended is equal to _bmi = sum
Solution 2:[2]
Simply, _bmi = int.parse(massNumber.text) + int.parse(heightNumber.text);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Taz |
| Solution 2 | Pathik Patel |
