skip to Main Content

The code is:

enter image description here

There’s a weird error saying that The argument type ‘Color?’ can’t be assigned to the parameter type ‘Color’ when I try to assign the color, what is going on here?

3

Answers


  1. You can use Theme.of(context) to get the color(and other property).

     color: color?? Theme.of(context).scaffoldBackgroundColor.withOpacity(.2)
    

    And try not to use ! without null check.

    Login or Signup to reply.
  2. color datatype is Color?
    please change the double datatype to Color?

    final double color; 
    to this 
    final Color? color;
    
    
    Login or Signup to reply.
  3. you can not assign double value to the color as you have defined color property of double data type.Change the data type of color to the Color like this:

    final Color color;
    

    if you wan to use hex color code you can do it like this

    Color(0xffb74093)
    

    in this the b74093 is the hex code of the color.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search