Jazil Zaim
Jazil Zaim

Reputation: 357

Non-nullable instance field 'painter' must be initialized in Flutter

Photo of the codeI am trying to figure out what is causing this error in the code. It seems like the painter side is causing issues. Been trying to figure this out for some time. I'd love any hints or tips on this. This seems like a change with Flutter 3.0 that took place I suppose.

BubbleIndicatorPainter({this.dxTarget = 125.0, this.dxEntry = 25.0, this.radius = 21.0,
this.dy = 25.0, required this.pageController}) : super(repaint: pageController) {
painter = Paint()
    ..color = CustomTheme.white
    ..style = PaintingStyle.fill;


}




Paint painter;
  final double dxTarget;
  final double dxEntry;
  final double radius;
  final double dy;

Upvotes: 0

Views: 39

Answers (2)

krishnaacharyaa
krishnaacharyaa

Reputation: 24950

Use

late Paint painter; 👈 Here late assures you will initiate the painter later in the program.

Or

Paint? painter;  👈 Here you are saying painter can be null to the dart compiler

This is error caused because of the dart null safety

Upvotes: 0

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63594

You can use late that you will assign data before reading it

late Paint painter;

Or you can make it nullable

 Paint? painter;

More about null-safety

Upvotes: 1

Related Questions