-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Updating from 0.3.3 to 0.4.1, it breaks my charts (LineChart and PieChart) #100
Comments
I will check, |
I will try to research more about it and give a proper example. It happens when i resize de view for example when i rotate the device |
Ok prepare a reproducers sample, It helps me to debug it faster. |
I found when does it happen but don't know how to solve it. It happens when the chart is inside a LayoutBuilder widget. class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (BuildContext context, constraints) => Center(
child: FractionallySizedBox(
heightFactor: 0.5,
widthFactor: 0.5,
child: Scaffold(
body: SafeArea(
child: PageView(
children: <Widget>[
LineChartPage(),
BarChartPage(),
BarChartPage2(),
PieChartPage(),
LineChartPage2(),
LineChartPage3(),
LineChartPage4(),
],
),
),
))));
}
} |
Dude you are trying to show the whole page with a 0.5 scale factor. |
Yes, sorry i was testing it on ipad and i wanted to check the resize when rotating. But I think for the example is not needed |
The error happens in containerRenderBox.size when the chart is a child of an upper tree that contains a LayoutBuilder. My usecase of LayoutBuilder: |
Run it with scale factor 1.0, |
I think it is related to this : widgets > BuildContext > findRenderObject
In this part of the code the RenderBox comes from the findRenderObject(). So probably when rotating it tries to get the size of the render box while the layout is being built. Size _getChartSize() {
if (_chartKey.currentContext != null) {
final RenderBox containerRenderBox = _chartKey.currentContext.findRenderObject();
return containerRenderBox.size;
} else {
return getDefaultSize(context);
}
} |
I replaced I don't understand much the |
Good catch! |
Good evening. I've tried @jamesblasco solution over a LayoutBuilder and it didn't work. Got same NEEDS-LAYOUT NEEDS-PAINT debug message. What I found though when I comment out the chartKey at CustomPaint of e.g LineChart class everything start to work as expected I haven't spotted any differences in behavior too. What it actually do? Is it crucial in this context? Might be a dumb question, sorry in advance) |
Given a size to the father container of my chart it throws this error.
The following assertion was thrown building PieChart(duration: 150ms, dirty, dependencies: [MediaQuery], state: PieChartState#f59ef(ticker active)):
RenderBox was not laid out: RenderCustomPaint#99bfc NEEDS-LAYOUT NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1687 pos 12: 'hasSize'
The text was updated successfully, but these errors were encountered: