Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
    ...
),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading