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

The following assertion was thrown during paint() - Flutter Web #384

Closed
jaxnz opened this issue Jul 2, 2020 · 4 comments
Closed

The following assertion was thrown during paint() - Flutter Web #384

jaxnz opened this issue Jul 2, 2020 · 4 comments
Labels
enhancement New feature or request Pie Chart

Comments

@jaxnz
Copy link

jaxnz commented Jul 2, 2020

Hi, I am getting the following exception when the widget builds.

The PieChartSection won't create if there is no value, so not sure whats happening

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during paint():
Assertion failed: org-dartlang-sdk:///flutter_web_sdk/lib/_engine/engine/validators.dart:11:7
!(rect.left.isNaN ||
          rect.right.isNaN ||
          rect.top.isNaN ||
          rect.bottom.isNaN)
"Rect argument contained a NaN value."

The relevant error-causing widget was: 
  PieChart file:///C:/Users/<User>/AndroidStudioProjects/<Project>/lib/views/admin/widgets/charts/enquiries_chart.dart:51:46
When the exception was thrown, this was the stack: 
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 214:49  throw_
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 24:3    assertFailed
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/validators.dart 14:15                      rectIsValid
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/ui/src/ui/canvas.dart 650:12                              drawArc
packages/fl_chart/src/chart/pie_chart/pie_chart_painter.dart 97:13                                                         [_drawSections]
...
The following RenderObject was being processed when the exception was fired: RenderCustomPaint#a1fab relayoutBoundary=up15
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=1145.0, h=442.0)
...  size: Size(923.3, 442.0)
RenderObject: RenderCustomPaint#a1fab relayoutBoundary=up15
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=1145.0, h=442.0)
  size: Size(923.3, 442.0)

Code:

class EnquiryPieChart extends StatelessWidget {
  final List<EnquiryData> enquiryData;
  EnquiryPieChart({this.enquiryData});

  @override
  Widget build(BuildContext context) {
    List<PieChartSectionData> pieSections = [];

    enquiryData.forEach((enquiry) {
      if (pieSections.where((section) => section.title == enquiry.hearAboutUs).toList().isEmpty) {
        int count = enquiryData.where((how) => how.hearAboutUs == enquiry.hearAboutUs).length;
        pieSections.add(PieChartSectionData(
          title: enquiry.hearAboutUs,
          value: count.toDouble(),
          radius: 60,
        ));
      }
    });
    return pieSections.isEmpty ? Loading() : PieChart(PieChartData(sections: pieSections));
  }
}

Flutter Version:

Flutter 1.19.0-4.1.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision f994b76974 (3 weeks ago) • 2020-06-09 15:53:13 -0700
Engine • revision 9a28c3bcf4
Tools • Dart 2.9.0 (build 2.9.0-14.1.beta)
@TavernierAlicia
Copy link

It seems the centerSpaceRadius value is mandatory.
In your return PieChart :
return PieChart( PieChartData( centerSpaceRadius: 0, // more settings ) )

@jaxnz
Copy link
Author

jaxnz commented Jul 6, 2020

@TavernierAlicia - worked perfectly! I'm thinking centerSpaceRadius may need @required?

@jaxnz jaxnz closed this as completed Jul 6, 2020
@imaNNeo
Copy link
Owner

imaNNeo commented Jul 9, 2020

Yes, we need @required for it.
I will reopen it to follow it up.
Thanks for letting us know.

@imaNNeo imaNNeo reopened this Jul 9, 2020
@imaNNeo imaNNeo added enhancement New feature or request Pie Chart labels Jul 10, 2020
imaNNeo added a commit that referenced this issue Jul 10, 2020
…red-radius

PieChartData set default centerSpaceRadius to double.infinity, #384.
@imaNNeo
Copy link
Owner

imaNNeo commented Jul 26, 2020

Set default centerSpaceRadius to double.infinity in PieChartData.
Check it out in the 0.11.0 version.
Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Pie Chart
Projects
None yet
Development

No branches or pull requests

3 participants