I have made a BMI calculator in flutter. I am new in flutter. After running the code i am receiving the above warning. Kindly provide me the solution of this problem. Below attached is the link of the code
- December 20, 2021
- 197 views
- 2 votes
- 3 Answers
-
3
Answers
You are declaring the
_result
variable as non-nullable,However you do a
null
checkSo change your variable declaration to this,
And then you can
null
check this wayYou declared the result variable like this:
_result
is the name of the variable,double
is the type.late
means you are not yet assigning a value to it.A late variable is different from a nullable variable in the sense that a nullable variable’s value could be null, a late variable doesn’t have a value until you assign one.
the above if will always be false because
xd
‘s value is not null, xd has no value at all.a nullable variable is determined with a
?
after the type:which means that if you haven’t assigned anything to it, it will be null, but you can also assign null directly.
the above is not possible for a
late
variable.Try changing the
extractedData
tojsonDecode(response.body)
from
to