Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

A value of type 'int' can't be assigned to a variable of type 'String'

A value of type ‘int’ can’t be assigned to a variable of type ‘String’.
Try changing the type of the variable, or casting the right-hand type to ‘String’.

TextFormField(
                    keyboardType: TextInputType.number,
                    controller: TextEditingController()
                      ..text = '${profileModel.phonenumber}',
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 17,
                      letterSpacing: 1,
                    ),
                    decoration: InputDecoration(
                      border: OutlineInputBorder(),
                      labelText: "Phone Number",
                      hintText: "enter your phonenumber",
                      floatingLabelBehavior: FloatingLabelBehavior.auto,
                      prefixIcon: Icon(Icons.phone),
                      focusedErrorBorder: OutlineInputBorder(),
                    ),
                    onChanged: (text) {
                      number = text as int;
                      print(number);
                    },
                  ),

CastError (type ‘String’ is not a subtype of type ‘int’ in type cast)

onChanged: (text) {
 number = text as int;
 print(number);
},

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

TextFormField(
     keyboardType: TextInputType.number,
      controller: TextEditingController()
      ..text = '${profileModel.phonenumber}',

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading