From 94df789f8cfb2e4b73595cd2e9d065a1127ae781 Mon Sep 17 00:00:00 2001 From: Magomed Dadagov Date: Thu, 13 Jun 2024 00:12:40 +0300 Subject: [PATCH] Keep the last X-axis offset when adding new candles to the beginning of the list --- lib/src/interactive_chart.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/src/interactive_chart.dart b/lib/src/interactive_chart.dart index e48c70b..e048aca 100644 --- a/lib/src/interactive_chart.dart +++ b/lib/src/interactive_chart.dart @@ -100,6 +100,16 @@ class _InteractiveChartState extends State { late Offset _initialFocalPoint; PainterParams? _prevParams; // used in onTapUp event + @override + void didUpdateWidget(covariant InteractiveChart oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.candles.length < widget.candles.length) { + // Change offset to show the latest candle when new data is added + _startOffset = + max(0, widget.candles.length * _candleWidth - _prevChartWidth!); + } + } + @override Widget build(BuildContext context) { return LayoutBuilder(