-2

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 **

  • 1
    You should not declare variables using `var` and not give the variable a value right away. The reason is that the determined type for these variables ends up being `dynamic` since Dart cannot know what type they are going to get. – julemand101 Jan 05 '22 at 09:03

2 Answers2

3

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)
{
    // ...
}
nvoigt
  • 75,013
  • 26
  • 93
  • 142
-1

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?

Mr. Eivind
  • 199
  • 2
  • 11
  • 1
    Don't use `runtimeType` for that. Use instead `if (latitude is double)`. `runtimeType` can lead you into some nasty problems and should be used rarely. – julemand101 Jan 05 '22 at 09:26