Reputation: 489
I define globally a variable as ui.Image _img1Global = null as ui.Image;
then I wanted to check to determine if the value is null or not.
if (_img1Global != null as ui.Image) {
canvasWrapper.save();
canvasWrapper.drawImage(
_img1Global, Offset(x, y - 2), new Paint());
canvasWrapper.restore();
}
I want to check if it is not null then I want to operate the drawImage but I keep getting error as type 'Null' is not a subtype of type 'Image' in type cast
at this if statement ? How to check if its filled with ui.Image and check its correct type?
I have even try this
_img1Global != null as ui.Image
? print("is null")
: print("is not null");
still I am getting same error ?
Upvotes: 0
Views: 1033
Reputation: 2503
null as ui.Image
It is throwing an error because the above code is telling that set null
type as an Image
type
To check the type of a variable use the runtimeType operator
if (_img1Global.runtimeType == Image) print('True')
Upvotes: 1