A RenderViewport expected a child of type RenderSliver but received a child of type RenderParagraph

Lee young-jun
2 min readMar 18, 2024

--

I changed the future list to stream for list. However my app crashed with this error. ๐Ÿ˜ž

The reason is CustomScrollViewโ€™s slivers cannot contain plain components like Text.

Practically, I implemented the view like this. ๐Ÿซข

slivers: [
...,
StreamBuilder(
stream: viewModel.parties,
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Text("Cannot load parties");
}

So how can we solve it? ๐Ÿค”

SliverToBoxAdapter is a solution. It will wrap Text with a sliver.

Full Source

StreamBuilder(
stream: viewModel.parties,
builder: (context, snapshot) {
if (snapshot.hasError) {
return const SliverToBoxAdapter(
child: Text("Cannot load parties"));
}

if (snapshot.connectionState ==
ConnectionState.waiting) {
return const SliverToBoxAdapter(
child: Text("Loading parties"));
}

return PartyListView(
list: snapshot.data!,
onSelectParty: viewModel.onPartySelected);
})

If you found this post helpful, please give it a round of applause ๐Ÿ‘. Explore more Flutter-related content in my other posts.

For additional insights and updates, check out my LinkedIn profile. Thank you for your support!

Reference

--

--

No responses yet