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: The getter 'spot' was called on null #53

Closed
bytesizedwizard opened this issue Aug 2, 2019 · 2 comments
Closed

Error: The getter 'spot' was called on null #53

bytesizedwizard opened this issue Aug 2, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@bytesizedwizard
Copy link
Contributor

bytesizedwizard commented Aug 2, 2019

Getting the below error every time the charts are drawn.

I/flutter (18757): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (18757): The following NoSuchMethodError was thrown during paint():
I/flutter (18757): The getter 'spot' was called on null.
I/flutter (18757): Receiver: null
I/flutter (18757): Tried calling: spot
I/flutter (18757): 
I/flutter (18757): When the exception was thrown, this was the stack:
I/flutter (18757): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
I/flutter (18757): #1      defaultTitlesStyle.<anonymous closure> (package:fl_chart/src/chart/base/axis_chart/axis_chart_data.dart:136:45)
I/flutter (18757): #2      MappedListIterable.elementAt (dart:_internal/iterable.dart:414:29)
I/flutter (18757): #3      ListIterable.toList (dart:_internal/iterable.dart:219:19)
I/flutter (18757): #4      defaultTitlesStyle (package:fl_chart/src/chart/base/axis_chart/axis_chart_data.dart:148:6)
I/flutter (18757): #5      AxisChartPainter.drawTouchTooltip (package:fl_chart/src/chart/base/axis_chart/axis_chart_painter.dart:128:56)
I/flutter (18757): #6      BarChartPainter.paint (package:fl_chart/src/chart/bar_chart/bar_chart_painter.dart:41:11)
I/flutter (18757): #7      RenderCustomPaint._paintWithPainter (package:flutter/src/rendering/custom_paint.dart:528:13)
I/flutter (18757): #8      RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:566:7)
I/flutter (18757): #9      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #10     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #11     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #12     RenderPointerListener.paint (package:flutter/src/rendering/proxy_box.dart:2669:11)
I/flutter (18757): #13     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #14     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #15     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #16     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #17     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #18     _RenderFlex&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2509:15)
I/flutter (18757): #19     RenderFlex.paint (package:flutter/src/rendering/flex.dart:947:7)
I/flutter (18757): #20     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #21     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #22     RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:70:15)
I/flutter (18757): #23     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #24     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #25     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #26     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #27     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #28     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #29     _RenderInkFeatures.paint (package:flutter/src/material/material.dart:510:11)
I/flutter (18757): #30     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #31     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #32     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #33     RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:569:11)
I/flutter (18757): #34     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #35     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #36     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #37     PaintingContext.pushLayer (package:flutter/src/rendering/object.dart:369:12)
I/flutter (18757): #38     RenderPhysicalShape.paint (package:flutter/src/rendering/proxy_box.dart:1818:15)
I/flutter (18757): #39     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #40     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #41     RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:70:15)
I/flutter (18757): #42     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #43     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #44     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #45     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #46     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #47     _RenderFlex&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2509:15)
I/flutter (18757): #48     RenderFlex.paint (package:flutter/src/rendering/flex.dart:947:7)
I/flutter (18757): #49     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #50     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #51     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #52     RenderDecoratedBox.paint (package:flutter/src/rendering/proxy_box.dart:1953:11)
I/flutter (18757): #53     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #54     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:172:13)
I/flutter (18757): #55     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:123:15)
I/flutter (18757): #56     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2089:7)
I/flutter (18757): #57     PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:127:11)
I/flutter (18757): #58     PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:95:5)
I/flutter (18757): #59     PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:858:29)
I/flutter (18757): #60     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:348:19)
I/flutter (18757): #61     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:701:13)
I/flutter (18757): #62     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:285:5)
I/flutter (18757): #63     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1016:15)
I/flutter (18757): #64     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:958:9)
I/flutter (18757): #65     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:874:5)
I/flutter (18757): #69     _invoke (dart:ui/hooks.dart:236:10)
I/flutter (18757): #70     _drawFrame (dart:ui/hooks.dart:194:3)
I/flutter (18757): (elided 3 frames from package dart:async)
I/flutter (18757): 
I/flutter (18757): The following RenderObject was being processed when the exception was fired: RenderCustomPaint#374c4:
I/flutter (18757):   creator: CustomPaint ← Listener ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← FlChart
I/flutter (18757):     ← Expanded ← Column ← Padding ← Semantics ← DefaultTextStyle ← AnimatedDefaultTextStyle ← ⋯
I/flutter (18757):   parentData: <none> (can use size)
I/flutter (18757):   constraints: BoxConstraints(w=323.2, h=116.2)
I/flutter (18757):   size: Size(323.2, 116.2)
I/flutter (18757): This RenderObject has no descendants.

Also, below is the code which I am using to draw the chart.

FlChart(
  chart: BarChart(
    BarChartData(
      barGroups: barChartGroupsData,
      titlesData: FlTitlesData(
        bottomTitles: SideTitles(
          showTitles: false,
        ),
        leftTitles: SideTitles(
          margin: 0.0,
          showTitles: false,
          getTitles: (tileIndex) {
            return tileIndex.toInt().toString();
          }
        )
      ),
      alignment: BarChartAlignment.spaceEvenly,
      backgroundColor: AppColors.white,
      borderData: FlBorderData(
        show: false
      ),
      gridData: FlGridData(
        drawHorizontalGrid: true,
      ),
      barTouchData: BarTouchData(
        enabled: false,
        touchTooltipData: TouchTooltipData(),
        allowTouchBarBackDraw: false,
      )
    ),
  ),
),

Any idea as to why this might be occuring? Thanks in advance for your help.
Also, many thanks for creating this awesome package!

@ashen-23
Copy link

touchTooltipData is the reason.

touchTooltipData: TouchTooltipData(
                          tooltipBgColor: Colors.blueGrey,
                          getTooltipItems: (touchedSpots) {
                            return touchedSpots.map((touchedSpot) {
                              if (touchedSpot?.spot == null) { return null; }  // ***** this is the key code
                              return TooltipItem('***' + '\n' + touchedSpot.spot.y.toString(), TextStyle(color: Colors.yellow));
                            }).toList();
                          }
                        )

@imaNNeo imaNNeo added the bug Something isn't working label Aug 15, 2019
@imaNNeo
Copy link
Owner

imaNNeo commented Aug 20, 2019

fixed in 0.2.0, the problem is that you forgot to set x in BarChartGroupData, now it is required

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

No branches or pull requests

3 participants