'Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null

I'm getting the below error in my code. I'm trying to create a stacked line graph using syncfusion_flutter_chart package. how to solve this. appreciate your help on this....... ......... .......................................................... enter image description here

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

class Chart extends StatefulWidget {
  const Chart({Key? key}) : super(key: key);

  @override
  _ChartState createState() => _ChartState();
}


class _ChartState extends State<Chart> {
  late TooltipBehavior _tooltipBehavior;

  @override
  void initState(){
    _tooltipBehavior =  TooltipBehavior(enable: true);
    super.initState();
   // WidgetsBinding.instance!.addPostFrameCallback((_) => yourFunction(context));
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
         child: Container(
           child: SfCartesianChart(
               tooltipBehavior: _tooltipBehavior,
               // Initialize category axis
               primaryXAxis: CategoryAxis(),
               series: <ChartSeries>[
               // Initialize line series
               LineSeries<ChartData, String>(
               // Enables the tooltip for individual series
               enableTooltip: true,
               dataSource: [
               // Bind data source
               ChartData('Jan', 35),
               ChartData('Feb', 28),
               ChartData('Mar', 34),
               ChartData('Apr', 32),
               ChartData('May', 40)
               ],
               xValueMapper: (ChartData data, _) => data.x,
               yValueMapper: (ChartData data, _) => data.y
           )],
           ),
         ),
      ),
    );
  }
}

class ChartData {
  ChartData(this.x, this.y);
  final String x;
  final double? y;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source