I have a stateful widget that draws a one from a list of points stored locally:
class Sparkline extends StatefulWidget {
@override
_Sparkline create() => _Sparkline;
}
class _Sparkline extends State<Sparkline> {
List<Offset> _points = [];
/// Add a new value and redraw
void add(double value) {
SetState(() {
points.add(value);
});
}
@override
void build(BuildState context) {
/// My sparkling custom painter that draw all points
return CustomPainter(...);
}
}
My idea would be to invoke the _Sparkline add() function anytime I've got a new value so that the sparkline redraws.
What's the best way to do that?