Flutter: Differences between SliverList and SliverFixedExtentList - flutter

What are the differences between SliverList and SliverFixedExtentList in Flutter?
According to the documentation of each widget:
SliverList: "A sliver that places multiple box children in a linear array along the main axis."
SliverFixedExtentList: "A sliver that places multiple box children with the same main axis extent in a linear array."
It seems that we should use SliverFixedExtentList over SliverList if all children have the same main axis extent. However, what does "same main axis extent" really mean?

It means all children have the same height. If you are familiar with ListView, it has itemExtent property that does the same thing.
Essentially, if you cannot guarantee all list items will have "equal size on the main axis" (e.g. equal height on a vertical scrolling list, or equal width on a horizontal scrolling list), then we cannot know the "exact size" of each item in the list, until we load it. However, if you can guarantee that they will all have the same size, for example, 100 units in height, then we don't need to load each item to measure its size.
Knowing item size before loading them is very useful when you want to jump a large distance. For example, if you want to scroll 10,000 px down, and if we know each item is fixed at 200 px tall, then we can easily jump 50 items, just load the 51th item and display it. If we don't know that (if you cannot guarantee that) then we will have to literally lay out all items in-between to see where 10,000 px will land us.

Related

What does an overflow mean?

While I debug my flutter app, at certain points I see warnings like this:
Bottom overflow by 1234 pixel
BoxConstraints have a negative value
I suppose, my concept of Flutter viewport / layout isn't correct:
Currently, I image an infinite drawing area, where I declaratively
define widgets.
Widgets, which are too large, get drawn outside the
viewport [or clipped].
Could you please refine my probably wrong concept?
This happens when the size [height, width] exceeds the the total size of the screen.
For example : the aspect ratio height of mobile screen is 500 and the size.height of button is 600, then the Bottom overflow by 100 pixel.
Generally overflow means, that the widget you want to paint on the screen crosses the border of the screen and therefore isn't visible anymore... This can also happen if you implement non scrollable columns in containers of a certain height... Usually, you can wrap your widget in a SingleChildScrollView widget and as a child choose a column/row (depending on the direction you want it to be aligned...) or make a list view and set the scrolldirection property to Axis.vertical or Axis.horizontal...

Widget that takes up a fixed maximum of space, but shrinks to make room for other widgets inside Row

My Flutter UI has a Row widget with and arbitrary number Widgets in it. I would like to move all of those widgets over to the right by a fixed amount. But the caveat is, if the other widgets grow in width such that the available horizontal space is consumed, the spacing widget will relinquish its space.
The Spacer widget does not work for me, as it does not allow you to specify a fix maximum. It only allows a flex value, which is a function of the width of the other content in the row. I want this spacer to take up a fixed amount of space regardless of the width of the other content of the row (unless all the room is used up).
Try using sizedBox or FractionallySizedBox as explained in this answer
https://stackoverflow.com/a/63430801/8213343

Unity Vertical Layout Group height not calculating off children

I feel like I am not understanding the Vertical Layout Group component in Unity 2020.3.21 and I am hoping that someone can explain what I am missing.
I have a series of runtime-controlled UI components that I want displayed vertically top-to-bottom. I need to be able to toggle these components on and off at run-time, and have the parent Vertical Layout Group size automatically update to the height of all of the active children. This is exactly the sort of thing the Vertical Layout Group is supposed to handle, right?
When I build out a simple example, I am seeing that the Vertical Layout Group correctly positions the children in a vertical list. However, it competely ignores the sizes of the children when measuring it's own height. This is a problem because I want to be able to throw this container in a Scroll View -- if the height is not accurate, then the Scroll View doesn't work properly.
Here's my demo. I have a series of children in a VLG that all have explicit set heights in their RectTransform. All of them are direct children of the VLG. None of them use a LayoutElement; all heights are explicitly defined in a RectTransform. Here's the scene hierarchy, with the compile-time RectTransform heights of each component in parenthesis.
Canvas (325x812)
GameObject (812)
Vertical Layout Group (100)
Text (45)
Spacer (100)
Text Input (48)
Spacer (20)
Button (48)
Here are my VLG settings:
When I run the game, I can see the outline of each UI object in the Scene tab. The children clearly have their heights set. Yet the VLG still has it's static compile-time height of 100 instead of the sum of the child heights.
Am I missing something about how the Vertical Layout Group works? How can I get this VLG to have it's Height property set to the actual total height of it's active children at runtime?
ContentSizeFitter with Vertical Fit set to preferred size should do the trick. I did a quick test using simplified structure based on your example and got height calculated correctly (height of children objects is 100+50+75):

How can I create an infinte grid in flutter?

I want to create a grid with large number of cells. On screen not all cells should be shown, but only some cells at the center of the screen.
Just like the app Desmos.
It should be possible to scroll from any direction in the app.
// THE PROBLEM IS WITH THE NEXT LINE , AS I DON'T THINK I CAN USE double.infinity.toInt() FOR INFINITE //NUMBER OF CELLS. AND EVEN IF IT WORKS HOW CAN I SET THE NUMBER OF CELLS IN A VERTICAL COLUMN TO //INFINITE OR ANY LARGE NUMBER.
GridView.count(crossAxisCount: double.infinity.toInt()),
.....
//Here is the code that will define the 4 Coordinates for each cell.
),
GridView.count creates a scrollable, 2D array of widgets with a fixed number of tiles in the cross axis.
What you need to use is some other GridView constructor like GridView.builder.
https://api.flutter.dev/flutter/widgets/GridView/GridView.builder.html
Creates a scrollable, 2D array of widgets that are created on demand.
This constructor is appropriate for grid views with a large (or
infinite) number of children because the builder is called only for
those children that are actually visible.

Unity list item is leaving extra space in high resolution

I have a vertical Scroll List. I have developed this app for resolution 768*1024. In this resolution my List is working fine. But when I run my app in higher resolution(1440*2960) it leave some space around all 4 direction.
I have also tried with changing Layout element min height dynamically, but Spacing issue is still exist.
Vertical and horizontal layout set element position in (screen width/height divided by a number of elements) * element number, in other words, they space out all elements evenly across canvas space. To achieve what you want you either have to enable child control size -> height option or write a script that aligns your elements in the center of the screen and one after another taking in consideration their height.