Fl_chart: error while clicking on pie chart

Created on 27 Dec 2019  ยท  9Comments  ยท  Source: imaNNeoFighT/fl_chart

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.

Pie Chart bug

All 9 comments

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

โ•โ•โ•โ•โ•โ•โ•โ• 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.

Provide me a reproducer code.

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

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

Waiting for the next version brother.

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

Fixed in 0.7.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kw2019ltd picture kw2019ltd  ยท  6Comments

caioflores picture caioflores  ยท  6Comments

atreeon picture atreeon  ยท  4Comments

davidmarinangeli picture davidmarinangeli  ยท  3Comments

alexodus picture alexodus  ยท  3Comments