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.
 
 

108 lines
3.2 KiB

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:teso/Pages/PageWidgets/Coupons/mycoupons.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:teso/Pages/Sub_Pages/@Generic/RedeemingCoupon.dart';
import 'package:teso/Pages/codeQR.dart';
import 'package:teso/Classes/API Clasess/CouponDetails.dart';
import 'package:flutter/cupertino.dart';
import 'package:teso/providers/pageAnimations.dart';
import 'package:teso/Pages/Sub_Pages/Coupons/MyCouponOptions.dart';
import 'package:teso/providers/user_provider.dart';
class MyCoupons extends StatefulWidget {
@override
_MyCouponsState createState() => _MyCouponsState();
}
class _MyCouponsState extends State<MyCoupons> {
SharedPreferences? prefs;
@override
void initState() {
super.initState();
}
void _scanQRCode(context, CouponDetails img) async {
String? result = await Navigator.push(
context,
PageTransition(
type: PageTransitionType.downToUp,
child: QRCodeScanner(),
),
);
if (result != null && result.isNotEmpty && result == img.businessId) {
await Navigator.push(
context,
PageTransition(
child: RedeemingCoupon(
couponDetails: img,
),
type: PageTransitionType.fade,
),
);
}
}
tesoCouponDialog(context, CouponDetails details) async {
showModalBottomSheet(
context: context,
isScrollControlled: true,
enableDrag: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0)),
),
builder: (BuildContext bc) {
return AcquiredOptions(
head: details,
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Consumer<UserProvider>(
builder: (context, value, child) {
// ignore: unnecessary_null_comparison
if (value == null) {
Provider.of<UserProvider>(context, listen: false).getCoupons();
return Container(
child: Center(
child: CupertinoActivityIndicator(
animating: true,
radius: 15,
),
),
);
} else if (value.mycoupons.length == 0) {
Provider.of<UserProvider>(context, listen: false).getCoupons();
return Container(
child: Center(
child: Text("No coupons available"),
),
);
} else {
return Container(
// margin: EdgeInsets.only(
// bottom: 80,
// ),
child: ListView.builder(
itemCount: value.mycoupons.length,
itemBuilder: (context, int index) {
return Column(
children: [
buildMyCoupons(context, value.mycoupons.elementAt(index),
tesoCouponDialog, _scanQRCode),
Divider(),
],
);
},
),
);
}
},
),
);
}
}