In Flutter, when creating a CustomPainter, there is an override method, shouldRepaint() that you can return either true or false... presumably to tell the system whether or not to repaint the view.
And in the docs, the description for the method is:
shouldRepaint(covariant CustomPainter oldDelegate) → bool Called whenever a new instance of the custom painter delegate class is provided to the RenderCustomPaint object, or any time that a new CustomPaint object is created with a new instance of the custom painter delegate class (which amounts to the same thing, because the latter is implemented in terms of the former). [...]
I basically don't understand any of that other than the fact that it returns a bool. That makes my head hurt! I also suspect that delving deeper into the definition of "custom painter delegate class," or "RenderCustomPaint object," will not be an enlightening experience.
I'm confused because:
I thought we didn't have to worry about when a widget "should repaint" because Flutter was supposed to decide where and when to re-render the widget tree based on it's own complex optimization decisions.
I thought the paint() method was where you define "this is how this view paints itself, (always and whenever that is necessary)"
All the examples I have found simply return false from this method... but I have noticed different behavior when using true vs false.
If we are always returning false, then how does it ever repaint? (And it does repaint even when false)
If the only possible logic available to us is comparing the "oldDelegate" to (something?) then why are we required to override the method at all?
I haven't seen any example that demonstrates why or how you would return TRUE, and what the logic of such an example would look like in order to make that decision.
Why and how would a knowledgable person decide to return false?
Why and how would a knowledgable person decide to return true?
Can anyone explain it like you're talking to a 13 year old (not Linus Torvalds)?
A simple code example and counter-example would be great (as opposed to an exhaustive explicit explanation!)