getChildSize always return 0 #4
Comments
Hi! Could you provide a code example to see how you're trying to do it? Thanks! |
My code look like this, i use setState to set the max height and max width of the DiagonalScrollView but like i said the getChildSize method always return 0 and since onCreated only called once the value is never change to the current size of the DataTable. return DiagonalScrollView(
enableFling: false,
enableZoom: false,
maxHeight: childHeight,
maxWidth: childWidth,
onCreated: (controller) {
Size childSize = controller.getChildSize();
setState(() {
childHeight = childSize.height;
childWidth = childSize.width;
});
},
child: DataTable(
// content load dynamically
),
); I've just change my code to this because calling setState during build throw error. But still the result of printing the height and width value resulting in 0. return DiagonalScrollView(
enableFling: false,
enableZoom: false,
// maxHeight: childHeight,
// maxWidth: childWidth,
onCreated: (controller) {
Size childSize = controller.getChildSize();
print('Height: ${childSize.height}, Width: ${childSize.width}');
},
child: DataTable(
// content load dynamically
),
); |
I have published a new version. Now onCreated is called after the Widget has been painted. You should be able to get the right child size and also setState inside onCreated. Could you try it? |
Thankyou for the update it's working as expected now the getChildSize method return the correct size of the child widget but there's one problem when calling setState inside onCreated. In my code i wrap DiagonalScrollView with FutureBuilder to get the data i need for the table, so when i called setState it rerender the whole page including the future builder, so now i'm stuck in a loop. I can maybe fix this issue on my part by implementing different way of handling state but maybe it would be nice if DiagonalScrollView can set it's own max size internally with the size of it's child? like adding a property called setSizeWithChildSize or something and if it's true then we handle the sizing internally. Let me know what you think. |
Glad to hear that the patch works! The new feature you suggest sounds great, I'll add it soon. |
So i use DiagonalScrollView to wrap my DataTable and because my table doesn't have a fix height and width i try to set a maxHeight and maxWidth using the size of my DataTable after it render using getChildSize from the controller.
The problem is it always return 0 both on the height and width and now my table scrolls infinitely on both direction.
The text was updated successfully, but these errors were encountered: