'The argument type 'double' can't be assigned to the parameter type 'VisualDensity?'

IconButton(//... visualDensity: VisualDensity.minimumDensity,), // The argument type 'double' can't be assigned to the parameter type 'VisualDensity?'. Why can't I assign?



Solution 1:[1]

The type of visualDensity is nullable. Try using VisualDensity.minimumDensity!

I also suggest adding a null check. VisualDensity.minimumDensity == null ? 0.0 : VisualDensity.minimumDensity!

Solution 2:[2]

So the next time you run into an error like this, what it is basically telling you is that you're trying to pass the wrong data to the parameter.

For your case this is what you should do

IconButton(onPressed: (){}, icon: Icon(Icons.enhance_photo_translate), visualDensity: VisualDensity(horizontal: 4.0, vertical: 4.0),)

Pass a visual density object and not a double primitive type.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tray Denney
Solution 2 Denzel