Skip to content

The following _CastError was thrown during paint(): Null check operator used on a null value #751

Closed
@mohitarora7272

Description

@mohitarora7272

Hello Team, First of all thanks for the awesome package. But i am facing some issue when i changed SplineRangeAreaSeries graph dynamically. Below is the error i got. Also i am using the latest version of your library syncfusion_flutter_charts: ^20.1.56

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following _CastError was thrown during paint():
Null check operator used on a null value

The relevant error-causing widget was:
CustomPaint
CustomPaint:file:///home/mohit/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_charts-20.1.56/lib/src/chart/base/chart_base.dart:3022:22

When the exception was thrown, this was the stack:
#0 SplineRangeAreaChartPainter.paint (package:syncfusion_flutter_charts/src/chart/series_painter/spline_range_area_painter.dart:411:49)
#1 RenderCustomPaint._paintWithPainter (package:flutter/src/rendering/custom_paint.dart:563:13)
#2 RenderCustomPaint.paint (package:flutter/src/rendering/custom_paint.dart:605:7)
#3 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2477:7)
#4 PaintingContext.paintChild (package:flutter/src/rendering/object.dart:187:13)
#5 RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:140:15)
#6 RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2477:7)
#7 PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:141:11)
#8 PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:100:5)
#9 PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:995:29)
#10 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:506:19)
#11 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:892:13)
#12 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:370:5)
#13 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1146:15)
#14 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1083:9)
#15 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:997:5)
#19 _invoke (dart:ui/hooks.dart:151:10)
#20 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#21 _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)

The following RenderObject was being processed when the exception was fired: RenderCustomPaint#572f2 relayoutBoundary=up2:
creator: CustomPaint ← RepaintBoundary ← Container ← Stack ← Container ← DecoratedBox ← Container ←
DecoratedBox ← ConstrainedBox ← Container ← Listener ← _GestureSemantics ← ⋯
parentData: (can use size)
constraints: BoxConstraints(0.0<=w<=663.1, 0.0<=h<=208.1)
size: Size(0.0, 0.0)
painter: SplineRangeAreaChartPainter#bbc9d(ValueNotifier#88647(42))
This RenderObject has no descendants.
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

Another exception was thrown: Null check operator used on a null value

This is my configuration

  • Flutter (Channel stable, 3.0.1, on Ubuntu 20.04.4 LTS 5.13.0-41-generic, locale en_IN)
  • Android toolchain - develop for Android devices (Android SDK version 31.0.0)
  • Chrome - develop for the web
  • Android Studio (version 2021.2)
  • Connected device (3 available)
  • HTTP Host Availability

Here is the code

Widget _chartWidget() {
    return SliverToBoxAdapter(
        child: Container(
      padding: EdgeInsets.only(left: 10.0, right: 10.0),
      height: MediaQuery.of(context).size.height / 1.6,
      child: Card(
        elevation: 5,
        child: chartData.length > 0
            ? SfCartesianChart(
                //zoomPanBehavior: _zoomPanBehavior,
                plotAreaBorderWidth: 0,
                title: ChartTitle(text: 'Product price comparison'),
                legend: Legend(isVisible: true),
                primaryXAxis: CategoryAxis(
                    isInversed: true,
                    majorGridLines: const MajorGridLines(width: 0),
                    labelPlacement: LabelPlacement.onTicks),
                primaryYAxis: NumericAxis(
                    axisLine: const AxisLine(width: 0),
                    labelFormat: r'${value}',
                    majorTickLines: const MajorTickLines(size: 0)),
                series: chartData.length > 0 ? _getSplineAreaSeries() : [],
                tooltipBehavior: TooltipBehavior(enable: true),
              )
            : Container(),
      ),
    ));
  }
  /// Returns the list of chart series
  /// which need to render on the spline range area chart.
  List<SplineRangeAreaSeries<ChartSampleData, String>> _getSplineAreaSeries() {
    return <SplineRangeAreaSeries<ChartSampleData, String>>[
      SplineRangeAreaSeries<ChartSampleData, String>(
        dataSource: chartData,
        color: const Color.fromRGBO(75, 135, 185, 0.5),
        borderColor: const Color.fromRGBO(75, 135, 185, 1),
        borderWidth: 3,
        borderDrawMode: RangeAreaBorderMode.excludeSides,
        xValueMapper: (ChartSampleData sales, _) => _commonUtils.changeDateFormat(sales.x, limit),
        highValueMapper: (ChartSampleData sales, _) => sales.y,
        lowValueMapper: (ChartSampleData sales, _) => sales.yValue,
        name: '${chartData[0].text}',
      ),
    ];
  }
mobizen_20220522_225402.mp4

Check above Video For Better Understanding of this issue. Please check and resolve this asap.
Thanks,
Mohit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions