Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82fcd47

Browse files
committed
fixed got stuck in loop problem, due to dispatching OnTouchEnd infinitely
1 parent 43d771e commit 82fcd47

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

lib/src/chart/bar_chart/bar_chart_painter.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ class BarChartPainter extends AxisChartPainter {
4040

4141
super.drawTouchTooltip(canvas, size, data.barTouchData.touchTooltipData, [touchedSpot]);
4242

43-
if (touchedResponseSink != null) {
43+
if (touchedResponseSink != null && touchInputNotifier != null
44+
&& touchInputNotifier.value != null
45+
&& !(touchInputNotifier.value.runtimeType is NonTouch)) {
4446
touchedResponseSink.add(BarTouchResponse(touchedSpot, touchInputNotifier.value));
47+
releaseIfEndTouch();
4548
}
4649
}
4750

@@ -342,6 +345,7 @@ class BarChartPainter extends AxisChartPainter {
342345
return null;
343346
}
344347

348+
345349
final touch = touchInputNotifier.value;
346350

347351
if (touch.getOffset() == null) {

lib/src/chart/base/base_chart/base_chart_painter.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {
104104
/// checks that the touchInput is eligible to draw,
105105
/// and child painters can use this function to check then draw their default touch behaviors.
106106
bool shouldDrawTouch() {
107-
if (touchInputNotifier == null || shouldDrawTouch == null) {
107+
if (touchInputNotifier == null
108+
|| touchInputNotifier.value == null
109+
|| shouldDrawTouch == null) {
108110
return false;
109111
}
110112

@@ -118,4 +120,11 @@ abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {
118120

119121
return true;
120122
}
123+
124+
/// if the event was ended, we should release our touchInputNotifier
125+
void releaseIfEndTouch() {
126+
if (touchInputNotifier.value is FlLongPressEnd || touchInputNotifier.value is FlPanEnd) {
127+
touchInputNotifier.value = NonTouch();
128+
}
129+
}
121130
}

lib/src/chart/base/base_chart/touch_input.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,12 @@ class FlPanEnd extends FlTouchNormapInput {
9090
return localPosition;
9191
}
9292

93+
}
94+
95+
96+
class NonTouch extends FlTouchInput {
97+
@override
98+
Offset getOffset() {
99+
return null;
100+
}
93101
}

lib/src/chart/line_chart/line_chart_painter.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ class LineChartPainter extends AxisChartPainter {
9797
// Draw touch tooltip on most top spot
9898
super.drawTouchTooltip(canvas, viewSize, data.lineTouchData.touchTooltipData, touchedSpots);
9999

100-
if (touchedResponseSink != null) {
100+
if (touchedResponseSink != null && touchInputNotifier != null
101+
&& touchInputNotifier.value != null
102+
&& !(touchInputNotifier.value.runtimeType is NonTouch)) {
101103
touchedResponseSink.add(LineTouchResponse(touchedSpots, touchInputNotifier.value));
104+
releaseIfEndTouch();
102105
}
103106
}
104107

lib/src/chart/pie_chart/pie_chart_painter.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ class PieChartPainter extends BaseChartPainter {
5353
drawTexts(canvas, size);
5454

5555
final touched = _getTouchedDetails(canvas, size, sectionsAngle);
56-
if (touchedResponseSink != null) {
56+
if (touchedResponseSink != null && touchInputNotifier != null
57+
&& touchInputNotifier.value != null
58+
&& !(touchInputNotifier.value.runtimeType is NonTouch)) {
5759
touchedResponseSink.add(touched);
60+
releaseIfEndTouch();
5861
}
5962
}
6063

0 commit comments

Comments
 (0)