Skip to content
This repository has been archived by the owner on Sep 24, 2023. It is now read-only.

getChildSize always return 0 #4

Closed
rakakhrl opened this issue Jul 1, 2020 · 5 comments
Closed

getChildSize always return 0 #4

rakakhrl opened this issue Jul 1, 2020 · 5 comments

Comments

@rakakhrl
Copy link

rakakhrl commented Jul 1, 2020

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.

@RanfiCD
Copy link
Owner

RanfiCD commented Jul 1, 2020

Hi!
I've tried to use a DataTable with DiagonalScrollView and assign maxWidth and maxHeight dynamically, considering the size of the DataTable, but I haven't been able to reproduce the issue.

Could you provide a code example to see how you're trying to do it?

Thanks!

@rakakhrl
Copy link
Author

rakakhrl commented Jul 2, 2020

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
            ),
          );

@RanfiCD
Copy link
Owner

RanfiCD commented Jul 2, 2020

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?

@rakakhrl
Copy link
Author

rakakhrl commented Jul 3, 2020

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.

@RanfiCD
Copy link
Owner

RanfiCD commented Jul 3, 2020

Glad to hear that the patch works!

The new feature you suggest sounds great, I'll add it soon.

@RanfiCD RanfiCD closed this as completed Jul 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants