I. Antonov
I. Antonov

Reputation: 707

Dart / Flutter The argument type 'Color' can't be assigned to the parameter type 'int'

I am trying to make the a Button in flutter reusable as it is pretty much the same except for the Color of the Button. As far as I understand from a number search results, the datatype for colors is Color. But when I do the following it gives me an error saying The argument type 'Color' can't be assigned to the parameter type 'int'.

class CustomButton extends StatelessWidget {
  final Color buttonColor;
  final Color textColor;

  const CustomButton({
    Key? key,
    required this.buttonColor,
    required this.textColor,
  }) : super(key: key);

And I mentioned it like the following:

style: TextStyle(
   fontSize: 16,
   fontWeight: FontWeight.bold,
   color: Color(textColor)),

Thanks in advance.

Upvotes: 1

Views: 421

Answers (1)

Moaz El-sawaf
Moaz El-sawaf

Reputation: 3039

The property color in the TextStyle accepts a value of type Color which is a dart object, not the integer value of the color code.

So you can keep textColor with type Color and use it like the following:

style: TextStyle(
    ...
    color: textColor // textColor is a variable of type Color
    ...
),

Or change the type of the textColor variable to be int containing the value (Color Code) of the color, example: 0xFFFF0000, and then use it like the following:

style: TextStyle(
    ...
    color: Color(textColor) // textColor is a variable of type int containing the color code
    ...
),

Upvotes: 1

Related Questions