How to constrain the width of GridView with a Scrollbar in Flutter? - 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

Related

Flutter expand/collapse container without overflow error

Does anybody have a clue how to achieve expand/collapse animation for a given Container widget?
I tried to use ExpandablePanel but it is not what I really want, because I want to render a Column within a Container, and if the Container is collapsed I want to show only 150px from it, otherwise it should have the height of the content.
Clicking on the arrow the Container should toggle it's state.
Below are some images which represents the goal:
Collapsed
Expanded
The overflow error is thrown because when the column is collapsed there is no room to contain all the children inside the column.
What do we do when we have a column with children's height larger than the screen height? We use scrolling!
So you can wrap your column with SingleChildScrollView widget to make the column scrollable, so when it collapses it doesn't complain about the children's height, instead, the scrolling functionality handles them because you can scroll in a column even if it has very small width.

GridView's shrinkWrap not shrink as small as possible in 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

Scrollbar + any scroll widget bug on scrolling in web

I need to use Scrollbar widget for web as it enables scrollbar always on AND the ability to edit its size and width. I also have to use it with a child that is scrollable (singlechildescrollview, listview, etc), but after updating to flutter 2.2, I've seen that 2 scrollbars appear on screen and keeps buging the experience (can be seen when changing the size of the scrollbar in the parent).
I've tryed to disable the scrolling in the child, but its scrollbar still shows. I cant use the default scrollbar in the child, as its more geared towards mobile.
Fixed using rawascrollbar. It removes any padding when pressing on the side of the screen, and gives the ability to change the color of scrollbar (that way hides the child scroll). Better then the Scrollbar widget.

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?

How to set flutter bottom sheet height fit with inner content?

how to control flutter bottom sheet height with its inner content without fixed height? totally I just want a height change with its inner content size
Use a ConstrainedBox give a minimum and maximum height and width as you need and the child of the ConsrainedBox should be your bottom sheet container and you are good to go.
Here is the youtube link on ConstrainedBox.
Here is more how you can deal with box constraints: https://flutter.dev/docs/development/ui/layout/box-constraints