flutterloop
flutterloop

Reputation: 578

trying to set Paint() color to primary theme

trying to set the color to the primary theme in my flutter app, get an error where context is saying The argument type 'PaintingContext' can't be assigned to the parameter type 'BuildContext'. any idea how to fix this?

   final paint = Paint()

  ..color = Theme.of(context).colorScheme.primary; //Thumb Background Color
  ..style = PaintingStyle.fill;

Upvotes: 0

Views: 574

Answers (2)

Mark Dionnie
Mark Dionnie

Reputation: 435

All you have to do is add a color property

class MyCustomPainter extends CustomPainter {
  final Color color;
  MyCustomPainter(this.color);

}

and then use it like

Container(
color: Colors.transparent,
width: double.infinity,
height: 70,
child: CustomPaint(
painter: MyCustomPainter(Theme.of(context).scaffoldBackgroundColor),),)

Upvotes: 0

Fabrizio
Fabrizio

Reputation: 1074

What might be happening is that you are trying to use a PaintingContext where you should use an object of type BuildContext. To solve this you could either pass the BuildContext or directly the color to the CustomPainter.

Upvotes: 1

Related Questions