Skip to content

Commit 4f942a5

Browse files
committed
[PR fluttercandies#26 feature] Keep the last X-axis offset when adding new candles to the beginning of the list
1 parent be5db97 commit 4f942a5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/src/interactive_chart.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ class _InteractiveChartState extends State<InteractiveChart> {
107107
late Offset _initialFocalPoint;
108108
PainterParams? _prevParams; // used in onTapUp event
109109

110+
@override
111+
void didUpdateWidget(covariant InteractiveChart oldWidget) {
112+
super.didUpdateWidget(oldWidget);
113+
if (oldWidget.candles.length < widget.candles.length) {
114+
// Change offset to show the latest candle when new data is added
115+
_startOffset =
116+
max(0, widget.candles.length * _candleWidth - _prevChartWidth!);
117+
}
118+
}
119+
110120
@override
111121
Widget build(BuildContext context) {
112122
return LayoutBuilder(

0 commit comments

Comments
 (0)