I want to repaint my RepaintBoundary widget's child every time the variable _lastIndex
changes in setState()
method. Basically, I want the same behaviour for RepaintBoundary as would apply to any normal Container - but for unrelated reasons I need a RepaintBoundary and not a Container. I played around and found out that the child (MyPainter
) gets re-rendered when _lastIndex
changes in the first example, but not in the second. What is the rule behind it that makes the behaviors of the two examples so different?
1.example
RepaintBoundary(
key: globalKey,
child: Container(
child: Container(
child: new CustomPaint(
child: Text(_lastIndex.toString()), // MyPainter is re-rendered because of this line
painter: new MyPainter(index: _lastIndex), // while this line doesn't have any effect on re-rendering
isComplex: true,
willChange: false,
),
)
)
),
2.example
RepaintBoundary(
key: globalKey,
child: Container(
child: Container(
child: new CustomPaint(
painter: new MyPainter(index: _lastIndex),
isComplex: true,
willChange: false,
),
)
)
),