Home > Mobile >  Type 'String' is not a subtype of type 'int' in type cast
Type 'String' is not a subtype of type 'int' in type cast

Time:04-05

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

Please help ASAP

CodePudding user response:

Actually, what you intended is equal to _bmi = sum

CodePudding user response:

Simply, _bmi = int.parse(massNumber.text) int.parse(heightNumber.text);

  • Related