A RenderViewport expected a child of type RenderSliver but received a child of type RenderParagraph
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.