Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error while clicking on pie chart #146

Closed
sohampandya00 opened this issue Dec 27, 2019 · 9 comments
Closed

error while clicking on pie chart #146

sohampandya00 opened this issue Dec 27, 2019 · 9 comments
Labels
bug Something isn't working Pie Chart

Comments

@sohampandya00
Copy link

Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
when i am tapping or long tapping some times. getting this error and after that i am not able to get touch event.

i solved it by changing in one file named "PieChartPainter".

sectionsAngle was null and we are getting value of it by index.

to temporary solve it. i made following changes.

  1. adding try catch.
  2. checking section Angle is null or not and checking its length.
try {
      for (int i = 0; i < data.sections.length; i++) {
        final section = data.sections[i];
        if(sectionsAngle!=null)
        {
          if(sectionsAngle.length > i ) {
            double sectionAngle = sectionsAngle[i];

            tempAngle %= 360;
            sectionAngle %= 360;

            /// degree criteria
            final space = data.sectionsSpace / 2;
            final fromDegree = tempAngle + space;
            final toDegree = sectionAngle + tempAngle - space;
            final isInDegree = touchAngle >= fromDegree &&
                touchAngle <= toDegree;

            /// radius criteria
            final centerRadius = data.centerSpaceRadius;
            final sectionRadius = centerRadius + section.radius;
            final isInRadius = touchR > centerRadius && touchR <= sectionRadius;

            if (isInDegree && isInRadius) {
              foundSectionData = section;
              foundSectionDataPosition = i;
              break;
            }

            tempAngle += sectionAngle;
          }
        }
      }
    } on Exception catch(e)
    {
      print("caught");

    }
    catch(e)
    {
      print("caught");
    }

I dont know my way is right or not as i ddnt go through whole library code. but i am not getting this error now. kindly guide.

@imaNNeo
Copy link
Owner

imaNNeo commented Dec 27, 2019

Hi there,
I didn't understand the problem,
may I ask you to provide a reproducible code (include the main function)?
Thanks!

@msarkrish
Copy link

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown while handling a gesture:
The method '[]' was called on null.
Receiver: null
Tried calling:

When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1 PieChartPainter._getTouchedDetails (package:fl_chart/src/chart/pie_chart/pie_chart_painter.dart:197:42)
#2 PieChartPainter.handleTouch (package:fl_chart/src/chart/pie_chart/pie_chart_painter.dart:170:12)
#3 PieChartState.build. (package:fl_chart/src/chart/pie_chart/pie_chart.dart:56:28)
#4 LongPressGestureRecognizer._checkLongPressEnd. (package:flutter/src/gestures/long_press.dart:333:52)
...
Handler: "onLongPressEnd"
Recognizer: LongPressGestureRecognizer#7f88e
debugOwner: GestureDetector
state: possible
════════════════════════════════════════════════════════════════════════════════════════════════════

i'm getting this error when long press the chart with given sample code.

@imaNNeo
Copy link
Owner

imaNNeo commented Jan 4, 2020

Provide me a reproducer code.

@imaNNeo
Copy link
Owner

imaNNeo commented Jan 5, 2020

It will be closed by tomorrow if you don't provide it.
Thanks!

@imaNNeo imaNNeo added the bug Something isn't working label Jan 7, 2020
imaNNeo added a commit that referenced this issue Jan 7, 2020
@imaNNeo
Copy link
Owner

imaNNeo commented Jan 7, 2020

Thank you, I found the problem.
It will be fixed in the next version,
stay tuned!

@msarkrish
Copy link

Waiting for the next version brother.

@imaNNeo
Copy link
Owner

imaNNeo commented Jan 9, 2020

Thanks for waiting,
the next version will be 0.7.0
stay tuned!
Thanks!

@imaNNeo
Copy link
Owner

imaNNeo commented Jan 18, 2020

Fixed in 0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Pie Chart
Projects
None yet
Development

No branches or pull requests

3 participants