I created a cart page. I have listed all the orders first then I have listviews under the cart items. But the page is scrollable only by touching the appbar , not by the stream builder cart items. Code for the Cart page:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
import 'package:provider/provider.dart';
import 'package:page_transition/page_transition.dart';
import '../../models/user.dart';
import '../../services/managedata.dart';
import '../home/bottom_navbar.dart';
class CartUI extends StatefulWidget {
const CartUI({Key? key}) : super(key: key);
@override
State<CartUI> createState() => _CartUIState();
}
class _CartUIState extends State<CartUI> {
@override
Widget build(BuildContext context) {
final user = Provider.of<Userr?>(context, listen: false);
return Scaffold(
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(
top: 40.0,
),
child: SingleChildScrollView(
child: Row(
children: [
IconButton(
icon: const Icon(
Icons.arrow_back_ios,
color: Colors.black,
),
alignment: Alignment.topLeft,
iconSize: 25,
onPressed: () {
Navigator.pushReplacement(
context,
PageTransition(
child: const BottomNavbar(),
type: PageTransitionType.rightToLeftWithFade));
}),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
SizedBox(
width: 300,
child: Text(
"Your Cart",
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Proxima',
letterSpacing: 1.0,
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 18.0,
),
),
),
],
),
],
),
),
),
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('myOrders')
.doc(user?.uid)
.collection('items')
.snapshots(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Lottie.asset('assets/animations/delivery.json'),
);
} else {
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data!.docs.length,
itemBuilder: (BuildContext context, int index) {
final DocumentSnapshot documentSnapshot =
snapshot.data!.docs[index];
return Container(
height: 120,
width: 300,
child: Row(
children: [
Column(
children: [
SizedBox(
width: 200,
child: Text(
documentSnapshot['name'],
style: const TextStyle(
color: Colors.black87,
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
),
Text(
documentSnapshot['quantity'].toString(),
style: const TextStyle(
fontSize: 15,
),
),
Text(
'Rs.${documentSnapshot['price'].toString()}',
style: const TextStyle(
color: Colors.black87,
fontSize: 15,
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
const SizedBox(
width: 40,
),
ElevatedButton(
onPressed: () {
if (documentSnapshot['value'] !=
0.0) {
setState(() {
String id =
documentSnapshot[
'docid'];
final user =
Provider.of<Userr?>(
context,
listen: false);
var postDocRef =
FirebaseFirestore
.instance
.collection(
'myOrders')
.doc(user?.uid)
.collection('items')
.doc();
Provider.of<ManageData>(
context,
listen: false)
.UpdateCart(
context,
{
'value':
documentSnapshot[
'value'] -
0.5,
'price': documentSnapshot[
'price'] -
(documentSnapshot[
'ogprice'] /
2),
},
id);
});
}
if (documentSnapshot['value'] ==
0.5) {
String id =
documentSnapshot['docid'];
Provider.of<ManageData>(
context,
listen: false)
.deleteData(context, id);
}
},
child: const Text('-'),
),
const SizedBox(width: 20),
Text(documentSnapshot['value']
.toString()),
const SizedBox(width: 20),
ElevatedButton(
onPressed: () {
String id =
documentSnapshot['docid'];
final user =
Provider.of<Userr?>(context,
listen: false);
var postDocRef =
FirebaseFirestore.instance
.collection('myOrders')
.doc(user?.uid)
.collection('items')
.doc();
Provider.of<ManageData>(context,
listen: false)
.UpdateCart(
context,
{
'value':
documentSnapshot[
'value']
0.5,
'price': documentSnapshot[
'price']
(documentSnapshot[
'ogprice'] /
2),
},
id);
},
child: const Text(' '),
),
]),
],
),
],
),
);
});
}
},
),
),
ListTile(
leading: Icon(Icons.shopping_bag
// color: AppColors.blackColor,
),
title: Text(
'Your Orders',
// style: TextStyles.highlighterTwo,
),
trailing: Icon(Icons.keyboard_arrow_right),
),
]),
],
),
),
);
}
}
How to make that stream builder cart items scrollable by touching on it?
I tried using SingleChildScrollView but that only helps in extending the page down but not making the cart items scrollable by touching on it.
CodePudding user response:
Add NeverScrollablePhysics to the listview builder?
physics: NeverScrollableScrollPhysics()