Flutter check if variable is NaN

Issue

I have var number; and it gets assigned by some calculations.

If I do print(number); I get NaN as response;

I expected that I would be able to do something like

if (number is NaN)

But I get NaN is not defined.
How to check if variable is NaN in flutter?

Solution

NAN is a CONSTANT so you can do this

if (number == double.nan)

also you have this property isNaN but to use it you must provide the type because it’s available only for nums so either double or int

if (number.isNaN)

Answered By – Raouf Rahiche

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.