Home > Net >  How can i check whether variable holds double value or null value in dart?
How can i check whether variable holds double value or null value in dart?

Time:01-06

For example i have declared two varaibles

var latitude;
var longitude;

**Now i want to check whether latitude or longitude or both hold double value or they are null **

CodePudding user response:

First, stop making your own life harder than it has to be, use the proper types:

double? latitude;
double? longitude;

if(latitude == null)
{
    // ...
}

if(longitude == null)
{
    // ...
}

CodePudding user response:

If you want to check if a value is null, you can simply do:

if (latitude === null) {
}

To check runtime types (e.g. checking if a variable is a double), one can use:

latitude.runtimeType

See How to perform runtime type checking in Dart?

  •  Tags:  
  • Related