I have this code and I am trying to make this gridview scrollable and no matter what I do it is not scrolling. I keep getting this renderoverflow error. I have tried to wrap it around SingleChildScroll view and also physics: ScrollPhysics() in its properties but nothing works. I just need to make this gridView scrollable and not the text below it. I have tried several ways but nothing as of now works for it. Might be a dumb mistake that I might be doing here but can't figure it out. Edit: It works fine when I set singleChildScrollView after that body tag of scaffold but does not work when I apply it to GridView.
class _CartGridViewState extends State<CartGridView> {
@override
Widget build(BuildContext context) {
final User user = FirebaseAuth.instance.currentUser;
double sum = 0;
print(user);
return StreamBuilder(
stream: FirebaseFirestore.instance
.collection('Users')
.doc(user.uid)
.collection('Cart')
.snapshots(),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
var document = snapshot.data.docs;
return Padding(
padding: const EdgeInsets.all(10.0),
child: SingleChildScrollView(
physics: ScrollPhysics(),
child: GridView.builder(
physics: ScrollPhysics(),
scrollDirection: Axis.vertical,
primary: false,
shrinkWrap: true,
itemCount: document.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.height / 800,
),
itemBuilder: (context, index) {
if (document[index].data()["name"] == null) {
return Text('There are $index items in cart');
} else {
return Card(
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CartView(
document[index].data()["name"],
document[index]
.data()["price"]
.toDouble(),
document[index].data()["image"],
index,
)),
);
},
child: Stack(children: [
ListView(physics: ScrollPhysics(), children: [
Hero(
tag: 'tagImage$index',
child: Image.network(
"${document[index].data()["image"]}",
height: 150,
),
),
Center(
child: Text(
"Price ${document[index].data()["price"]}")),
]),
DeleteCartItems(index),
]),
),
);
}
}),
),
);
},
);
}
}