Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type 'int' is not a subtype of type double this error coming #5

Open
Samikhanonco opened this issue Apr 6, 2020 · 18 comments
Open

Comments

@Samikhanonco
Copy link

type 'int' is not a subtype of type double this error coming

@Rohan2309
Copy link

use var

@Rohan2309
Copy link

I got the similar problem. I used var then it got solved.

@Samikhanonco
Copy link
Author

thanx bro

@simplygkgk
Copy link

Where to replace var??
@Samikhanonco

@alihusainsorathiya
Copy link

@simplygkgk @Samikhanonco instead of double temp replace it with var temp

@azeemgujjar
Copy link

seems Dart is totally garbage

@gaetanosestito
Copy link

gaetanosestito commented Aug 19, 2020

Hi, I solved using var temp

    var temp = weatherData['main']['temp'];
    temperature = temp.toInt();

thanks @Rohan2309

@sandeep1dimri
Copy link

i observed that for some cities or (latitude and longitude), the JSON return temperature as int, example like below (23 not 23.00)
{coord: {lon: -xxx, lat: xxx}, weather: [{id: 800, main: Clear, description: clear sky, icon: 01n}], base: stations, main: {temp: 23

so 23 is int not double. so i made generic change to convert it to double and then it works well.
setState(() {
double temp = (weatherData['main']['temp']).toDouble();

@rohitsinghkcodes
Copy link

just initialize temperature with int then store the fetched location's temperature temporarily in var at last typecast it in int
int temperature;
.
.
var temp = weatherData['main']['temp'];
temperature = temp.toInt();

@reyad2020
Copy link

Hi, I solved using var temp

    var temp = weatherData['main']['temp'];
    temperature = temp.toInt();

thanks @Rohan2309

thanx it worked

@reyad2020
Copy link

thanx it worked

@looloo404
Copy link

Hi, I solved using var temp

    var temp = weatherData['main']['temp'];
    temperature = temp.toInt();

thanks @Rohan2309

I got the similar problem. I used var then it got solved.

thanks to you i can solve proplem

@kiranojhanp
Copy link

#26
Avoid use of var. Its better to use dart as strongly tyoed.

@Nisa-fatima369
Copy link

i observed that for some cities or (latitude and longitude), the JSON return temperature as int, example like below (23 not 23.00) {coord: {lon: -xxx, lat: xxx}, weather: [{id: 800, main: Clear, description: clear sky, icon: 01n}], base: stations, main: {temp: 23

so 23 is int not double. so i made generic change to convert it to double and then it works well. setState(() { double temp = (weatherData['main']['temp']).toDouble();

unfortunately , I have the sem issue but the solution isn't workin well with my case

@zoenie123
Copy link

zoenie123 commented Oct 23, 2022

use var

No ... use num instead of double in this case. Always avoid var when possible.

  num? temperature;
  temperature = weatherData['main']['temp'];

or

  num temperature = 0.0;
  temperature = weatherData['main']['temp'];

I consider it also bad API design when numeric values flip between double and int in json, but unfortunately we have to deal with it in this case.

@rifat-22
Copy link

rifat-22 commented Dec 20, 2022

use var

No ... use num instead of double in this case. Always avoid var when possible.

  num? temperature;
  temperature = weatherData['main']['temp'];

or

  num temperature = 0.0;
  temperature = weatherData['main']['temp'];

I consider it also bad API design when numeric values flip between double and int in json, but unfortunately we have to deal with it in this case.

@zoenie123 , There is a workaround if the json data flips between double and int. This helped me. Take a look.
https://stackoverflow.com/a/62396418/11445727

@zoenie123
Copy link

@rifat-22 I stand with my solution, it's the most simple and fast one. All other versions I have seen do conversion on conversion. No need.

@Woyinkuro
Copy link

Hi, I solved using var temp

    var temp = weatherData['main']['temp'];
    temperature = temp.toInt();

thanks @Rohan2309

I tried this but it didn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests