Umair Jibran
Umair Jibran

Reputation: 483

How do I send and/or Receive Colors as argument in Flutter

here is the declaration of 'colour' final Colors colour;

this is the method/constructor where I will be receiving a color from my main.dart

MyCardState(
    myQuestion: myQuestion,
    myColor: colour,
    opA: myOptionA,
    opB: myOptionB
  )

But I have no idea how to send a color from my main.dart. I tried colour: Colors.cyan but it won't work.

Upvotes: 2

Views: 5266

Answers (2)

Umair Jibran
Umair Jibran

Reputation: 483

problem solved I was supposed to use final Color colour instead of final Colors colour

Upvotes: 0

Ricardo Markiewicz
Ricardo Markiewicz

Reputation: 977

You should use the class Color, in singular:

class MyCardState {
  final Color color;

  MyCardState({this.color});
}

Also, keep in mind that some colors in Colors.* are instances of MaterialColor and not Color.

Upvotes: 6

Related Questions