Skip to content

Commit 20dada0

Browse files
authored
Merge pull request #60 from imaNNeoFighT/bugfix/loop
Bugfix/loop
2 parents 43d771e + 495bab0 commit 20dada0

File tree

10 files changed

+49
-13
lines changed

10 files changed

+49
-13
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0
2+
* fixed a critical got stuck in draw loop bug,
3+
* set `BarChartGroupData` x as required property to keep consistency and prevent unpredictable bugs
4+
15
## 0.1.6
26
* added `enableNormalTouch` property to chart's TouchData to handle normal taps, and enabled by default.
37

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Thank you all!
3636

3737
```kotlin
3838
dependencies:
39-
fl_chart: ^0.1.6
39+
fl_chart: ^0.2.0
4040
```
4141

4242

example/lib/line_chart/samples/line_chart_sample1.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ class LineChartSample1State extends State<LineChartSample1> {
2020
super.initState();
2121

2222
controller = StreamController();
23-
controller.stream.distinct().listen((LineTouchResponse response){
24-
print('response: ${response.touchInput}');
25-
});
23+
controller.stream.distinct().listen((LineTouchResponse response){});
2624
}
2725

2826
@override

lib/src/chart/bar_chart/bar_chart_data.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ class BarChartGroupData {
129129
/// to draw them independently by y value together.
130130
/// [barsSpace] is the space between the bar lines inside group
131131
const BarChartGroupData({
132-
this.x,
132+
@required this.x,
133133
this.barRods = const [],
134134
this.barsSpace = 2,
135-
});
135+
}): assert(x != null);
136136

137137
/// calculates the whole width of our group,
138138
/// by adding all rod's width and group space * rods count.

lib/src/chart/bar_chart/bar_chart_painter.dart

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ class BarChartPainter extends AxisChartPainter {
3838
drawBars(canvas, size, groupBarsPosition);
3939
drawTitles(canvas, size, groupBarsPosition);
4040

41-
super.drawTouchTooltip(canvas, size, data.barTouchData.touchTooltipData, [touchedSpot]);
41+
if (touchedSpot != null) {
42+
super.drawTouchTooltip(canvas, size, data.barTouchData.touchTooltipData, [touchedSpot]);
43+
}
4244

43-
if (touchedResponseSink != null) {
45+
if (touchedResponseSink != null && touchInputNotifier != null
46+
&& touchInputNotifier.value != null
47+
&& !(touchInputNotifier.value is NonTouch)) {
4448
touchedResponseSink.add(BarTouchResponse(touchedSpot, touchInputNotifier.value));
49+
releaseIfEndTouch();
4550
}
4651
}
4752

@@ -342,6 +347,7 @@ class BarChartPainter extends AxisChartPainter {
342347
return null;
343348
}
344349

350+
345351
final touch = touchInputNotifier.value;
346352

347353
if (touch.getOffset() == null) {
@@ -389,7 +395,7 @@ class BarChartPainter extends AxisChartPainter {
389395
}
390396
}
391397

392-
return BarTouchedSpot(null, null, null, null);
398+
return null;
393399
}
394400

395401
@override

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

+15-1
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,16 @@ 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 == null) {
127+
return;
128+
}
129+
if (touchInputNotifier.value == null
130+
|| touchInputNotifier.value is FlLongPressEnd
131+
|| touchInputNotifier.value is FlPanEnd) {
132+
touchInputNotifier.value = NonTouch();
133+
}
134+
}
121135
}

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

+8
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

+4-1
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

+4-1
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

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: fl_chart
22
description: A powerful Flutter chart library, currently supporting Line Chart, Bar Chart and Pie Chart.
3-
version: 0.1.6
3+
version: 0.2.0
44
author: Iman Khoshabi <[email protected]>
55
homepage: https://github.com/imaNNeoFighT/fl_chart
66

0 commit comments

Comments
 (0)