'how to make a gridview whose items can change index
I want to make certain grid items disappear. I use the Visibility widget but in the gridview the item does not disappear from the grid list, what should I do?
GridView.count(
shrinkWrap: true,
crossAxisCount: 2,
mainAxisSpacing: 7.5,
crossAxisSpacing: 7.5,
physics: NeverScrollableScrollPhysics(),
children: [
Visibility(
visible: false,
child: Container(
color: Colors.green,
child: Center(
child: Text('1'),
),
),
),
Visibility(
visible: true,
child: Container(
color: Colors.green,
child: Center(
child: Text('2'),
),
),
),
Visibility(
visible: true,
child: Container(
color: Colors.green,
child: Center(
child: Text('3'),
),
),
),
],
)
what I want
Solution 1:[1]
Visibilityis used to show or hide a child.
If you want to remove physical space, use if statement
if (false)
Container(
color: Colors.green,
child: Center(
child: Text('1'),
),
),
You can also use else state
if(visible) MyVisibleWidget()
else MyEmptyWidget(),
For if else you can also choose replacement on Visibility widget. I am not using replacement in this case because it will eventually add a child in replace of visible: false, which is not what we want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yeasin Sheikh |


