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.

228 lines
8.8 KiB

// ignore_for_file: unnecessary_null_comparison
import 'dart:async';
3 years ago
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:location/location.dart';
import 'package:teso/Pages/Sub_Pages/@Generic/prominentDisclosure.dart';
import 'package:teso/Pages/Sub_Pages/Coupons/CouponLocation.dart';
import 'package:teso/providers/pageAnimations.dart';
import 'package:teso/util/SizeConfig.dart';
import 'package:teso/util/consts.dart';
import 'package:teso/Classes/API Clasess/CouponDetails.dart';
import 'package:flutter_countdown_timer/flutter_countdown_timer.dart';
buildMyCoupons(BuildContext context, CouponDetails coupon, Function dialog,
Function scan) {
SizeConfig().init(context);
return InkWell(
onTap: () => dialog(context, coupon),
child: Container(
width: MediaQuery.of(context).size.width,
height: 100,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey,
width: 0.5,
),
borderRadius: BorderRadius.only(
topRight: Radius.circular(30),
topLeft: Radius.circular(30),
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
),
child: CachedNetworkImage(
imageUrl: productURL + coupon.targetProduct!.productImage!,
3 years ago
imageBuilder: (context, imageProvider) => Image(
width: MediaQuery.of(context).size.width * 0.28,
height: 110,
fit: BoxFit.fill,
image: imageProvider,
),
),
),
),
Container(
width: SizeConfig.safeBlockHorizontal * 50,
height: 80,
padding: EdgeInsets.all(5),
child: Center(
child: Column(
children: [
Container(
width: double.infinity,
child: Text(
"Item Name : " + coupon.targetProduct!.productName!,
3 years ago
style: TextStyle(
fontSize: SizeConfig.safeBlockHorizontal * 2.8,
),
),
),
Container(
width: double.infinity,
child: Text(
"Shop Name : " + coupon.issuer!.businessName!,
3 years ago
style: TextStyle(
fontSize: SizeConfig.safeBlockHorizontal * 2.8,
),
),
),
Container(
width: double.infinity,
child: CountdownTimer(
endTime: coupon.expiration!.millisecondsSinceEpoch,
3 years ago
widgetBuilder: (context, time) {
int? day = time!.days;
int? hours = time.hours;
int? min = time.min;
int? sec = time.sec;
3 years ago
if (time.min == null) min = 0;
if (time.days == null) day = 0;
if (time.hours == null) hours = 0;
if (time.sec == null) sec = 0;
if (time == null) {
return Text('Calculating..');
} else if (time.days == null || time.days! < 1) {
3 years ago
return Text(
"Expires in : ${hours}h : ${min}m : ${sec}s",
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.bold,
fontSize: SizeConfig.safeBlockHorizontal * 2.8,
),
);
} else if (time.days == 1) {
return Text(
"Expires in : ${day}day, ${hours}h : ${min}m : ${sec}s",
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
fontSize: SizeConfig.safeBlockHorizontal * 2.8,
),
);
} else {
return Text(
"Expires in : ${day}days, ${hours}h : ${min}m : ${sec}s",
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
fontSize: SizeConfig.safeBlockHorizontal * 2.8,
),
);
}
},
),
//Text("Expires : " + "00:00.0"),
),
Container(
width: double.infinity,
child: Text(
"Pay only : GH¢ " +
(coupon.targetProduct!.unitPrice! -
(coupon.targetProduct!.unitPrice! *
(coupon.lowerLimit! / 100)))
3 years ago
.toStringAsFixed(2),
style: TextStyle(
color: Colors.red,
fontSize: SizeConfig.safeBlockHorizontal * 2.8,
),
),
),
],
),
),
),
new Wrap(
direction: Axis.vertical,
children: [
Container(
width: SizeConfig.safeBlockHorizontal * 25,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.all(
// Radius.circular(20.0),
// ),
// ),
primary: tesoBlue,
),
onPressed: () async {
PermissionStatus alreadyConsent =
await Location.instance.hasPermission();
if (alreadyConsent != PermissionStatus.granted) {
bool results = await (Navigator.push(
3 years ago
context,
PageTransition(
child: ProminentDisclosure(),
type: PageTransitionType.leftToRight)) as FutureOr<bool>);
3 years ago
if (results) {
await Location.instance.requestPermission();
Navigator.push(
context,
PageTransition(
type: PageTransitionType.leftToRight,
child: CouponLocator(
shop: coupon.issuer,
),
),
);
}
} else {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.leftToRight,
child: CouponLocator(
shop: coupon.issuer,
),
),
);
}
},
child: Text(
"Location",
style: TextStyle(
color: Colors.white,
),
),
),
),
Container(
width: SizeConfig.safeBlockHorizontal * 25,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
primary: accentMain,
),
onPressed: () => scan(context, coupon),
child: Text("Redeem"),
),
),
],
),
],
),
),
);
}