I like to use final members in my classes whenever it makes sense, but I ran into a problem trying to do something relatively simple:
import 'dart:ui';
class Foo {
final PictureRecorder recorder;
final Canvas canvas;
final int margin;
Foo({
this.margin = 10,
}) : recorder = PictureRecorder(),
canvas = Canvas(recorder) { // this line errors out
}
}
The error I'm getting from the compiler is:
The instance member 'recorder' can't be accessed in an initializer. Try replacing the reference to the instance member with a different expression
Is there another way of doing what I want without making the canvas field non-final?
I know I can make the class look similar "from the outside" using a non-final private field and a custom getter, but it feels like an unnecessary workaround.