Reputation: 3054
I am using StaggeredGridView in one of my Flutter project. I wanted to not load few tiles depending on the data availability.
For example. I am showing 5 tiles out of which 3 are dependent on the data available from network. Sometimes it may take 10 to 15 seconds. Right now if I return a Container() until my data gets loaded then also it holds the whole space in the layout.
I just don't want to add that tile to the grid if the data is not available or taking long to load. Once loaded it should be shown.
Thanking you in advance
Upvotes: 1
Views: 1336
Reputation: 10861
When you create your StaggeredGridView
, set the staggeredTiles
property and make sure you pass in StaggeredTile.fit(1)
for the tiles that you want to hide. This way the tile will wrap it's content so if there's not content it will be hidden.
Upvotes: 2
Reputation: 1228
Widget build(BuildContext context) {
return StreamBuilder<GridData>(
stream: [Stream end point] // your stream url,
builder: (context, snapshot) {
if (!snapshot.hasData) return LoadingSpinner();
return [View that you want to return]; // Your grid code.
}
)
}
Sample code
Upvotes: 2