Flutter Screenshot package error on Syncfusion Charts

65 views Asked by At

I am using the screenshot package to get the image bytes and then add it to the pdf in syncfusion in flutter. While the screenshot package seems to be working for my own custom paint widgets, it keeps giving me this error when i try using it on a syncfusion chart widget.

Error: No MediaQuery ancestor could be found starting
from the context that was passed to MediaQuery.of(). This can happen because the context used is not a descendant of a View widget, which introduces a
MediaQuery.

This is an example of what the screenshot widget holds currently:

await screenshotController.captureFromWidget( Scaffold(
      body: SfCartesianChart(
      isTransposed: true,
      title: ChartTitle(text: 'Tonnes Moved by Week Days'),
      legend: Legend(isVisible: true),
      primaryXAxis: CategoryAxis(title: AxisTitle(text: 'Week Days'), majorGridLines: MajorGridLines(width: 0), minorGridLines: MinorGridLines(width: 0)),
      primaryYAxis: NumericAxis(title: AxisTitle(text: 'Amount of Tonnes'),majorGridLines: MajorGridLines(width: 0), minorGridLines: MinorGridLines(width: 0)),
      series: <ChartSeries>[
        // Stacked Bar Series
        StackedBarSeries<ChartData, String>(
          dataSource: getStackedBarData(),
          xValueMapper: (ChartData data, _) => data.weekDay,
          yValueMapper: (ChartData data, _) => data.barValue,
          name: 'Stacked Bar Series',
        ),
      
        // Line Series
        LineSeries<ChartData, String>(
          color: redAlertColor,
          dataSource: getLineData(),
          xValueMapper: (ChartData data, _) => data.weekDay,
          yValueMapper: (ChartData data, _) => data.lineValue,
          name: 'Line Series',
         
        ),
      ],
        ),
    ),
  ).then((Uint8List? values) async {
    sampleBarChartBytes = values!;
    saveListToFile(sampleBarChartBytes.toString(), "Testing");
  });

I have so far tried wrapping it in a materialapp, in a mediaquery. However, none of it has worked. I have tried to separate it from the screenshot code and putting it in a separate widget, however I am unsure of why this error keeps coming up.

0

There are 0 answers