slovenian_boy
slovenian_boy

Reputation: 35

The element type Color can't be assigned to the list type Color

I have colors imported from another file named colors.dart and i don't know why can't I do this now...please help

enter image description here

Upvotes: 3

Views: 3679

Answers (2)

PREET VITHANI
PREET VITHANI

Reputation: 1

remove the [] brackets like,

colors:rdeca

Upvotes: -1

aaronlukacs
aaronlukacs

Reputation: 489

As the error message indicates, you are trying to assign a variable type Color? (which is actually Color OR null) to a list of type Color.

You can either change the declaration of the list to accept nullable values or you can make a type assertion by adding ! (only if you are sure that the value is not null.)

Like,

colors: [
   rdeca!,
   oranzna!
]

Upvotes: 4

Related Questions