0

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,
          ),
         )
        )
      ),
Coding Glass
  • 137
  • 1
  • 7
  • so you want `RenderBox.markNeedsPaint()` method to be called? in your case `RenderRepaintBoundary.markNeedsPaint()`? – pskink Dec 23 '20 at 15:59
  • Yes, that's it! I didn't even know that this method exists, so thank you!! – Coding Glass Dec 23 '20 at 16:18
  • but hjonestly if you just want your `CustomPainter` to be "repainted" then use `repaint` parameter in `CustomPainter` constructor - it is much easier imho – pskink Dec 23 '20 at 17:06

0 Answers0