I’m trying to add an overlay to a GridView in Flutter. The effect I want to achieve is for my grid to initially appear blocked, and then, for example after a button click, remove the overlay and show the underlying content. However, every attempt I make results in a full-screen overlay or I must declare a fixed height but for a GridView that is adaptive is not a great choice.
This is what I am trying to do:
But my widgets look like this:
That’s my code:
Stack(
children: [
GridView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 12,
mainAxisSpacing: 12),
itemCount: myList.length,
itemBuilder: (
context,
index,
) {
return Container(
width: 50,
height:50,
decoration: BoxDecoration(
border: Border.all(color: Colors.black)
),
}),
Center(
child: Container(
width: double.infinity,
color: Colors.grey,
),
)],
),
Thank you all
3
Answers
Try this version; it might resolve your problem:
The GridView is wrapped in a Visibility widget that controls its visibility based on the boolean variable isOverlayVisible. The overlay is implemented using a semi-transparent Container positioned at the same level as the GridView. A button (an ElevatedButton in this case) is positioned using the Positioned widget to toggle the isOverlayVisible boolean, thus controlling the visibility of the overlay.
You almost there:
You can just wrap that container with positioned widget to force it to cover the whole stack:
If you got the above snippet of code, it’s the same as that named constructor:
This named constructor just use a zero for each attribute top , left, right and bottom.
actually there is a
Widget
calledOverlay
which is made for this:Here’s a code :
You can use the same
Positioned
withStack
alsoHope that’s help !!!