Skip to content

Commit

Permalink
Merge pull request #66 from imaNNeoFighT/hotfix/touch-response-null
Browse files Browse the repository at this point in the history
Hotfix/touch response null
  • Loading branch information
imaNNeo committed Sep 11, 2019
2 parents 117522c + 3acbbc7 commit 872b0f7
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.2.1
* fixed #64, added a technichal debt :(

## 0.2.0
* fixed a critical got stuck in draw loop bug,
* set `BarChartGroupData` x as required property to keep consistency and prevent unpredictable bugs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Thank you all!

```kotlin
dependencies:
fl_chart: ^0.2.0
fl_chart: ^0.2.1
```


Expand Down
11 changes: 11 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/iman/Dev/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/iman/IdeaProjects/fl_chart/example"
export "FLUTTER_TARGET=/Users/iman/IdeaProjects/fl_chart/example/lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/iman/Dev/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
4 changes: 0 additions & 4 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -40,7 +39,6 @@
/* Begin PBXFileReference section */
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -73,7 +71,6 @@
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
3B80C3931E831B6300D905FE /* App.framework */,
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
9740EEBA1CF902C7004384FC /* Flutter.framework */,
Expand Down Expand Up @@ -190,7 +187,6 @@
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
1 change: 1 addition & 0 deletions fl_chart.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
Expand Down
21 changes: 18 additions & 3 deletions lib/fl_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ class _FlChartState extends State<FlChart> {
onLongPressStart: (d) {
_touchInputNotifier.value = FlLongPressStart(d.localPosition);
},
onLongPressEnd: (d) {
onLongPressEnd: (d) async {
_touchInputNotifier.value = FlLongPressEnd(d.localPosition);
_releaseTouch();
},
onLongPressMoveUpdate: (d) {
_touchInputNotifier.value = FlLongPressMoveUpdate(d.localPosition);
},
onPanCancel: () {
onPanCancel: () async {
_touchInputNotifier.value = FlPanEnd(Offset.zero);
_releaseTouch();
},
onPanEnd: (DragEndDetails details) {
onPanEnd: (DragEndDetails details) async {
_touchInputNotifier.value = FlPanEnd(Offset.zero);
_releaseTouch();
},
onPanDown: (DragDownDetails details) {
_touchInputNotifier.value = FlPanStart(details.localPosition);
Expand All @@ -84,6 +87,18 @@ class _FlChartState extends State<FlChart> {
);
}

void _releaseTouch() {
// bugFix to this issue: https://github.com/imaNNeoFighT/fl_chart/issues/64
// the problem is that wen user touches on screen we notify the touch result
// via touchResponseSink, and the listener tries to change the state of chart,
// then the chart again puts the new touchResult inside the touchResponseSink,
// and it got stuck in a loop, now we pass a NonTouch to break the loop
// Todo: we should find a better way to handle it
Future<dynamic>.delayed(Duration(milliseconds: 100)).then((dynamic s) {
_touchInputNotifier.value = NonTouch();
});
}

@override
void dispose() {
super.dispose();
Expand Down
1 change: 0 additions & 1 deletion lib/src/chart/bar_chart/bar_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class BarChartPainter extends AxisChartPainter {
touchInputNotifier.value != null &&
!(touchInputNotifier.value is NonTouch)) {
touchedResponseSink.add(BarTouchResponse(touchedSpot, touchInputNotifier.value));
releaseIfEndTouch();
}
}

Expand Down
12 changes: 0 additions & 12 deletions lib/src/chart/base/base_chart/base_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,4 @@ abstract class BaseChartPainter<D extends BaseChartData> extends CustomPainter {

return true;
}

/// if the event was ended, we should release our touchInputNotifier
void releaseIfEndTouch() {
if (touchInputNotifier == null) {
return;
}
if (touchInputNotifier.value == null ||
touchInputNotifier.value is FlLongPressEnd ||
touchInputNotifier.value is FlPanEnd) {
touchInputNotifier.value = NonTouch();
}
}
}
1 change: 0 additions & 1 deletion lib/src/chart/line_chart/line_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class LineChartPainter extends AxisChartPainter {
touchInputNotifier.value != null &&
!(touchInputNotifier.value.runtimeType is NonTouch)) {
touchedResponseSink.add(LineTouchResponse(touchedSpots, touchInputNotifier.value));
releaseIfEndTouch();
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/src/chart/pie_chart/pie_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class PieChartPainter extends BaseChartPainter {
&& touchInputNotifier.value != null
&& !(touchInputNotifier.value.runtimeType is NonTouch)) {
touchedResponseSink.add(touched);
releaseIfEndTouch();
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: fl_chart
description: A powerful Flutter chart library, currently supporting Line Chart, Bar Chart and Pie Chart.
version: 0.2.0
version: 0.2.1
author: Iman Khoshabi <iman.neofight@gmail.com>
homepage: https://github.com/imaNNeoFighT/fl_chart

Expand Down

0 comments on commit 872b0f7

Please sign in to comment.