You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
7.4 KiB
176 lines
7.4 KiB
3 years ago
|
import 'package:teso/Classes/TesoUser.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:teso/Pages/PageWidgets/Recently%20Viewed/viewedItem.dart';
|
||
|
import 'package:teso/Classes/API Clasess/CouponDetails.dart';
|
||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:provider/provider.dart';
|
||
|
import 'package:teso/providers/user_provider.dart';
|
||
|
import 'package:teso/Classes/API Clasess/Product.dart';
|
||
|
import 'package:teso/Classes/API Clasess/TesoBusinessDetail.dart';
|
||
|
import 'package:teso/Classes/API Clasess/CouponHead.dart';
|
||
|
import 'package:teso/Pages/Sub_Pages/Coupons/Acquire.dart';
|
||
|
|
||
|
class Recently extends StatefulWidget {
|
||
|
@override
|
||
|
_RecentlyState createState() => _RecentlyState();
|
||
|
}
|
||
|
|
||
|
class _RecentlyState extends State<Recently> {
|
||
|
TesoUser currentUser;
|
||
|
int _limit = 20;
|
||
|
final int _limitIncrement = 20;
|
||
|
List<QueryDocumentSnapshot> coupons = new List.from([]);
|
||
|
final ScrollController listScrollController = ScrollController();
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
listScrollController.addListener(_scrollListener);
|
||
|
super.initState();
|
||
|
}
|
||
|
|
||
|
_scrollListener() {
|
||
|
if (listScrollController.offset >=
|
||
|
listScrollController.position.maxScrollExtent &&
|
||
|
!listScrollController.position.outOfRange) {
|
||
|
setState(() {
|
||
|
_limit += _limitIncrement;
|
||
|
});
|
||
|
}
|
||
|
if (listScrollController.offset <=
|
||
|
listScrollController.position.minScrollExtent &&
|
||
|
!listScrollController.position.outOfRange) {
|
||
|
setState(() {});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
tesoCouponDialog(context, CouponsHead head, double price) {
|
||
|
showModalBottomSheet(
|
||
|
context: context,
|
||
|
isScrollControlled: true,
|
||
|
enableDrag: true,
|
||
|
shape: RoundedRectangleBorder(
|
||
|
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
|
||
|
),
|
||
|
builder: (BuildContext bc) {
|
||
|
return AcquireCoupon(
|
||
|
head: head,
|
||
|
price: price,
|
||
|
);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Consumer<UserProvider>(
|
||
|
builder: (BuildContext context, UserProvider user, Widget child) {
|
||
|
if (user == null) {
|
||
|
return Center(
|
||
|
child: CupertinoActivityIndicator(
|
||
|
animating: true,
|
||
|
radius: 15,
|
||
|
),
|
||
|
);
|
||
|
} else {
|
||
|
currentUser = user.currentUser;
|
||
|
return StreamBuilder(
|
||
|
stream: FirebaseFirestore.instance
|
||
|
.collection('recentlyViewed')
|
||
|
.doc("users")
|
||
|
.collection(currentUser.userGUID)
|
||
|
.orderBy('dateViewed', descending: true)
|
||
|
.limit(_limit)
|
||
|
.snapshots(),
|
||
|
builder: (context, snapshot) {
|
||
|
if (!snapshot.hasData) {
|
||
|
return Center(
|
||
|
child: CircularProgressIndicator(
|
||
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||
|
Theme.of(context).primaryColor)));
|
||
|
} else if (snapshot.data == null || coupons == null) {
|
||
|
return Center(
|
||
|
child: CircularProgressIndicator(
|
||
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||
|
Theme.of(context).primaryColor)));
|
||
|
} else {
|
||
|
coupons = snapshot.data.docs;
|
||
|
return ListView.builder(
|
||
|
itemCount: coupons.length,
|
||
|
controller: listScrollController,
|
||
|
itemBuilder: (context, int index) {
|
||
|
if (coupons.length <= 0) {
|
||
|
return Container();
|
||
|
} else {
|
||
|
CouponDetails couponDetails = new CouponDetails();
|
||
|
couponDetails.issuer = new TesoBusinessDetail();
|
||
|
couponDetails.targetProduct = new Product();
|
||
|
couponDetails.businessId =
|
||
|
snapshot.data.docs[index].data()['businessId'];
|
||
|
couponDetails.couponId =
|
||
|
snapshot.data.docs[index].data()['couponId'];
|
||
|
couponDetails.expiration = DateTime.parse(snapshot
|
||
|
.data.docs[index]
|
||
|
.data()['expiration']
|
||
|
.toString());
|
||
|
couponDetails.type =
|
||
|
snapshot.data.docs[index].data()['type'];
|
||
|
couponDetails.quantity = int.parse(snapshot
|
||
|
.data.docs[index]
|
||
|
.data()['quantity']
|
||
|
.toString());
|
||
|
couponDetails.worth = double.parse(snapshot
|
||
|
.data.docs[index]
|
||
|
.data()['worth']
|
||
|
.toString());
|
||
|
couponDetails.state =
|
||
|
snapshot.data.docs[index].data()['state'];
|
||
|
couponDetails.productCost = double.parse(snapshot
|
||
|
.data.docs[index]
|
||
|
.data()['unitPrice']
|
||
|
.toString());
|
||
|
couponDetails.issuer.businessAddress =
|
||
|
snapshot.data.docs[index].data()['businessAddress'];
|
||
|
couponDetails.issuer.businessContact =
|
||
|
snapshot.data.docs[index].data()['businessContact'];
|
||
|
couponDetails.issuer.businessDescription = snapshot
|
||
|
.data.docs[index]
|
||
|
.data()['businessDescription'];
|
||
|
couponDetails.issuer.businessLat =
|
||
|
snapshot.data.docs[index].data()['businessLat'];
|
||
|
couponDetails.issuer.businessLng =
|
||
|
snapshot.data.docs[index].data()['businessLng'];
|
||
|
couponDetails.issuer.businessLogo =
|
||
|
snapshot.data.docs[index].data()['businessLogo'];
|
||
|
couponDetails.issuer.businessName =
|
||
|
snapshot.data.docs[index].data()['businessName'];
|
||
|
couponDetails.targetProduct.productID =
|
||
|
snapshot.data.docs[index].data()['productId'];
|
||
|
couponDetails.targetProduct.productName =
|
||
|
snapshot.data.docs[index].data()['name'];
|
||
|
couponDetails.targetProduct.productImage =
|
||
|
snapshot.data.docs[index].data()['productImage'];
|
||
|
couponDetails.targetProduct.unitPrice = double.parse(
|
||
|
snapshot.data.docs[index]
|
||
|
.data()['unitPrice']
|
||
|
.toString());
|
||
|
couponDetails.lowerLimit = double.parse(snapshot
|
||
|
.data.docs[index]
|
||
|
.data()['lowerLimit']
|
||
|
.toString());
|
||
|
couponDetails.upperLimit = double.parse(snapshot
|
||
|
.data.docs[index]
|
||
|
.data()['upperLimit']
|
||
|
.toString());
|
||
|
return buildRecentItem(
|
||
|
context, couponDetails, tesoCouponDialog);
|
||
|
}
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|