Home > Net >  Error: Method 'toDouble' cannot be called on 'int?' while creating an app on Flu
Error: Method 'toDouble' cannot be called on 'int?' while creating an app on Flu

Time:06-24

Hi I am having an error while creating an app on Flutter

Error: Method 'toDouble' cannot be called on 'int?' because it is potentially null.
Try calling using ?. instead.
                          value: SliderValue.toDouble(),

                                             ^^^^^^^^

Anyone can help me

Error Screenshots

  1. First
  2. Second

CodePudding user response:

SliderValue can be null. you probably have it defined somewhere as

int? SliderValue;

You could change it to

int SliderValue = 0;

to fix it, or alternatively use

value: SliderValue?.toDouble() ?? 0,

to handle the case of when it's null

CodePudding user response:

Add '?' to the SliderValue:

SliderValue?.toDouble()

  • Related