Present an empty view in a Flutter widget to be used in the slivers of a CustomScrollView - flutter

Related question:
How to present an empty view in flutter?
Like that question, I need to return an empty view from Widget.build to indicate that there is nothing to render, but of course cannot return null. The widget will be used in the slivers of a CustomScrollView.
However, the suggestions from the answers to that question give errors when trying to use them in a Sliver (for example SizedBox.shrink()).
It seems that an empty const SliverToBoxAdapter() works.
Is this the best way?

The CustomScrollView needs Sliver type widgets.
SizedBox, Container, Row, Column, etc are not Sliver types at all.
So you need to convert them using SliverToBoxAdapter / SliverList / etc
SliverToBoxAdapter(child: SizedBox.shrink()) seems the more explicit to me yeah

Related

Why is expanded widget is destroying my UI in flutter after publishing it on play store

I have developed an application in Flutter Dart and used an Expanded widget in my application but wherever I used expanded widget, it destroyed my UI and converted that List into an infinite list with no data on it.
Please let me know that reason why does this occur and the potential solution.
Thank you everyone in advance
You can use the expanded widget inside the column and row. Sometimes with use of an expanded widget with the wrong widget will give the error in release mode while it is working in the debug mode.
Make sure you are using the expanded widget inside the column or row and that column and row should not be inside the scroll view or other scrollable widgets.
If still not clear then update the question with the widget hierarchy.

Is building one large better than building small ~75-100 widgets

Consider the case that I have 3 adjacent list view with each list view having a sized widget of some height. Each list view has around 24 child items. I'm trying to scale the widget using onScaleUpdate in GestureDetector.
onScaleUpdate I want to change the height of each child item of all the 3 listviews.
Is rebuilding all child better or should I rebuild the whole widget?
As #Yeasin Sheikh pointed out, using ListView.builder is good because it builds only the needed children (the ones inside the screen and just a few ones outside as precaution). And as to actually answering your question, I'm no Flutter expert, but using ListView.builder I don't think it makes that much difference, Flutter is intelligent enough to solve this by itself.

How to return a combination of SliverAppBar and SliverList in flutter

I have an app that has a cart screen, in this screen I want to divide the ordered products according to their respective factories, so I want to use SliverAppBars and SliverLists.
Now what I really need is to make a custom widget that can returns a SliverAppBar and a SliverList together so that I build this widget and get multiple SliverAppBars and SliverLists.
Anyone knows how to do that?
I found a package on pub.dev that can do that, it's called sliver_tools and here's the link to it here

In which circumstances should you use listview instead of listview.builder?

Like the topic I was wondering of there are any circumstances one should use the regular ListView instead of the ListView.builder in flutter, like if there are few items in a list could the ListView give better performance?
ListView has actually four different ways to use it , But let discuss ListView and ListView.builder
ListView : It has a children
property that takes a collection of static widgets. A ListView takes a small number of other widgets and makes it scrollable. Why a “small number”? Because this is designed to be a static list, one that you, the developer, simply types into the build() method
by hand.
ListView.builder : ListView’s alternative constructor, ListView.builder receives two
parameters, an itemCount and an ItemBuilder property that is a
function. This makes the ListView lazy-loaded. The itemBuilder function
dynamically creates children widgets on demand. As the user scrolls close
to the bottom of the list, itemBuilder creates new items to be scrolled into
view. And when we scroll something far enough off the screen, it is paged
out of memory and disposed of. Pretty cool.
Reference : taken from Rap Payne's Beginning App Development with Flutter (Great Book for beginners! , not an affiliate link).
official documentation for ListView .
ListView is the most commonly used scrolling widget. It displays its children one after another in the scroll direction. So if you just want to show some widgets below earch other and you need to scroll them you use ListView.
ListView.builder is a way of constructing the list where children’s (Widgets) are built on demand. However, instead of returning a static widget, it calls a function which can be called multiple times (based on itemCount ) and it’s possible to return different widget at each call.
I guess the simple answer you were looking for is:
Use ListView.builder whenever you iterate over an array of 'similar' elements.
Use ListView when items in your list are completely different from one another.
Think of ListView as scrollable Column

Differences between SliverList vs ListView in Flutter

What are the differences between SliverList and ListView in Flutter?
There's almost no difference.
ListView is a SliverList. Same with GridView, which is a SliverGrid.
They are doing exactly the same thing. The only difference between them is that SliverList is a sliver, not a widget. Which means it's used inside a ScrollView, usually CustomScrollView.
ListView is nothing else but a biding of SliverList to transform it into a Widget to make it usable alongside other widgets such as Row/Container.
Most of the time, use ListView.
But if you want advanced scroll behavior such as appbar animations with scroll ; you'll need to use a CustomScrollView. Which will force you to use SliverList instead of ListView.
According this article,
All of the scrollable views you use, like ListView and GridView,
are actually implemented using Slivers. You can kind of think of
Slivers as a lower-level interface, providing finer-grained control on
implementing scrollable area. Because slivers can lazily build each
item just as it scrolls into view, slivers are particularly useful for
efficiently scrolling through large numbers of children.