GridView's shrinkWrap not shrink as small as possible in flutter? - flutter

I create a GridView in flutter with the shrinkWrap set to true (which I expect the GridView will be shrink exactly as the content's size).
But in my demo (Green background color indicates GridView , and the Red Color indicates the content widgets in the GridView)
I found that , the GridView will not shrink as small as possible to it's contents. The GridView's height is a bit larger than the GridView's content height .
What makes the GridView not shrink as small as possible?

OK, after debugging with the source code . I found the reason to this problem:
Seems when you create a ListView & GridView with a null padding passing to it . Flutter SDK will make a Inset (RenderSliverPadding)during the layout of the ListView&GridView.
So the way to remove this padding is set a padding in the ListView&GridView's constructor

Related

Make scroll responsive to size of column in flutter

I have a screen with a column in flutter which is basically a form. At first i had trouble with the fact that the pop-up keyboard reduced the visible space and thus had an overflow. Fixed that adding the SingleChildScrollView and setting a container as a parent with an specific height (based on devicequery size).
Unfortunately, when I test the rotated screen, i get the same problem. Is there a way to set the height of the container which controls the SingleChildScrollView so that it adjusts to the total size occupied by the column widgets?
Please add Listview instead of Colum Widget.
in your scaffold
set resizeToAvoidBottomInset to false or add it
resizeToAvoidBottomInset:false

How to let resize and also give margin for whole screen in Flutter?

I want to give a margin around the whole screen in Flutter. So I put my content inside a Column and put the Column inside a Container. So I gave a padding to the whole screen. But when a TextField is selected and the keyboard appears the bottom overflow. I can't give resizeToAvoidBottomPadding: false, because then the keyboard covers the TextField.
I can't use SingleChildScrollView or a ListView because then the placing of the children won't keep space between.
It seems the only option is to remove the Container and set a padding to each child of the Column.
Is there a better option for this ?

How to constrain the width of GridView with a Scrollbar in Flutter?

I am trying to display a scrollbar on the right-hand side of a ScrollView (a GridView in this case) but constraining the width of the scrollable area while still displaying a scrollbar on the right-hand side. I can't see how to customize the position of the scrollbar relative to the Scrollable
See this DartPad for an example.
In the example above, the ScrollBar is displayed directly to the right hand side of the GridView's children, but I would prefer to have it all the way to the right. I can't find any affordances in the GridView constructor to help me with this. Does this require a CustomScrollView or can this be achieved with a normal GridView?
It is necessary that this GridView to have exactly 400px in width? If this is not necessary you can set the width of your ConstrainedBox like:
width: MediaQuery.of(context).size.width,
Then the GridView will have the exact size as your screen, so in consequence th scroll bar will be where you want it to be.
The fix was to swap the Center and Scrollbar widgets.
Before:
Center
Scrollbar
ConstrainedBox
After:
Scrollbar
Center
ConstrainedBox
https://dartpad.dev/09ddf64d254b0c331920cf970acc4447

Twitching Scrollbar in listview with dynamic height children

Code example: https://gist.github.com/v1z4/4c231063b9e22eac5961fb0c437119fe
I have a list of dynamic elements with different height, and I need to have a scrollbar. I use iOS style widgets, so I have wrapped ListView in CupertinoScrollbar().
I test it in real device attached, because simulator does not have scrollbar.
The list works fine, but scrollbar is twitching, because the height of elements are different.
It works fine when I add fixed height to container in ListView element, but text is being cropped and looks bad. Is there a way to fix twitching?

flutter gridView child height is fixed, add other widget cannot show?

here:
below the picture there is an inline text, but it is not visible. Maybe be the picture's height takes up the whole height? Any idea?
You are using GridView.builder. Instead you can use GridView.count.
In GridView.count, there is a parameter childAspectRatio which you can use to increase the height of the grid.