'Is there any way to use colspan with GridView.builder in Flutter?
I'm using GridView.builder and looking for a way to add colspan for a specific child to take the full width.
In the below example, I have a 2-column GridView which each column represents a product, but whenever user reaches to the end of the list, I want to show a loading indicator, which in this case it is shown in the first column on the left. I want the Center
widget to take 2 columns space like colspan=2
and show the loading indicator in the center.
GridView.builder(
itemCount: products.length + 1,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 8,
mainAxisSpacing: 8,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 1.8),
),
itemBuilder: (BuildContext context, int index) {
if (index >= products.length) {
return const Center(child: CircularProgressIndicator());
}
return ProductListItem(product: products[index]);
},
),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|