1

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?

TechAurelian
  • 5,561
  • 5
  • 50
  • 65

1 Answers1

0

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

Jscti
  • 14,096
  • 4
  • 62
  • 87