Robin
Robin

Reputation: 5427

The argument type 'MaterialColor' can't be assigned to the parameter type 'Paint'

enter image description here

I want to set the background color red, but there is no 'backgroundColor' property under TextStyle widget.

There is background property but i can't set the value for background. It shows error & the error is

The argument type 'MaterialColor' can't be assigned to the parameter type 'Paint'

The error is reasonable, i know. But what should be the value of background property ?

I search but unfortunately can't find :( I can set background as background: Paint() and the background goes to black. But i need red background. What should be the value of background ?

Thanks

Upvotes: 7

Views: 16532

Answers (2)

user11644496
user11644496

Reputation:

Instead of using background to define a color, I advise you to use directly the backgroundColor property like this:

   Text(
        'Wow',
        style: TextStyle(backgroundColor: Colors.red),
      ),

Upvotes: 1

Rémi Rousselet
Rémi Rousselet

Reputation: 276947

Simply set color property of Paint to Colors.red

Text(
  "Hello",
  style: TextStyle(background: Paint()..color = Colors.red),
),

Upvotes: 11

Related Questions