import 'package:flutter/material.
dart';
import 'package:gap/[Link]';
import 'package:garpo_application/widgets/vertical_dashlines.dart';
import '../utils/app_layout.dart';
import '../utils/app_styles.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
class Voucher extends StatefulWidget {
final Map<String, dynamic> vouch;
final Function(int)? onRedeem;
const Voucher({Key? key, required [Link], [Link]})
: super(key: key);
@override
_VoucherState createState() => _VoucherState();
}
class _VoucherState extends State<Voucher> {
final FirebaseAuth auth = [Link];
final FirebaseFirestore firestore = [Link];
Future<void> _redeemPoints() async {
final currentUser = [Link];
if (currentUser != null) {
String uid = [Link];
try {
DocumentSnapshot docSnapshot =
await [Link]('Users').doc(uid).get();
// Access the 'qrData' field from the document snapshot
if ([Link]) {
int garpoPoints = [Link]('Points');
int voucherPoints = [Link]['vpts'];
if (garpoPoints >= voucherPoints) {
await [Link]('Users').doc(uid).update({
'Points': garpoPoints - voucherPoints,
});
[Link]?.call(voucherPoints);
[Link](context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.check_circle, color: [Link]),
SizedBox(width: 10),
Text('Successfully Redeemed',
style: TextStyle(color: [Link])),
],
),
backgroundColor: [Link],
behavior: [Link],
duration: Duration(seconds: 3),
shape: RoundedRectangleBorder(
borderRadius: [Link](10),
),
margin: [Link](20),
elevation: 5,
),
);
} else {
[Link](context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon([Link], color: [Link]),
SizedBox(width: 10),
Text('Insufficient Points!',
style: TextStyle(color: [Link])),
],
),
backgroundColor: [Link],
behavior: [Link],
duration: Duration(seconds: 3),
shape: RoundedRectangleBorder(
borderRadius: [Link](10),
),
margin: [Link](20),
elevation: 5,
),
);
}
} else {
// print('Document does not exist');
}
} catch (e) {
// print(e);
}
}
}
@override
Widget build(BuildContext context) {
//print('Ticket number is ${ticket['number']}');
final size = [Link](context);
return SizedBox(
width: [Link] * 0.85,
height: [Link](105),
child: SingleChildScrollView(
scrollDirection: [Link],
child: Container(
margin: [Link](
right: [Link](10), bottom: [Link](5)),
child: Row(
mainAxisSize: [Link],
children: [
//P200off
Container(
width: [Link](88),
decoration: BoxDecoration(
color: const Color(0xFF526799),
borderRadius: [Link](
topLeft: [Link]([Link](21)),
bottomLeft: [Link]([Link](21))),
),
padding: [Link]([Link](12)),
child: Row(
children: [
Column(
mainAxisAlignment: [Link],
children: [
RichText(
text: TextSpan(
style: Styles.headLineStyle2
.copyWith(color: [Link]),
//style: [Link]([Link]),
children: <TextSpan>[
const TextSpan(text: "₱"),
TextSpan(
text: "${[Link]['vworth']}",
style: Styles.headLineStyle1
.copyWith(color: [Link])),
])),
Gap([Link](3)),
Text(
"Available until",
style: Styles.headLineStyle6
.copyWith(color: [Link], fontSize: 7),
),
Text(
"${[Link]['vexpire']}",
style: Styles.headLineStyle6
.copyWith(color: [Link], fontSize: 7),
),
],
)
],
),
),
//lines
Container(
width: [Link](15),
//padding: [Link]([Link](6)),
color: const Color(0xFF526799), //const Color (0xFFF37B67),
child: Column(
children: [
SizedBox(
height: [Link](10),
width: [Link](20),
child: DecoratedBox(
decoration: BoxDecoration(
color: [Link],
borderRadius: [Link](
bottomRight:
[Link]([Link](20)),
bottomLeft:
[Link]([Link](20)),
))),
),
Container(
height: [Link](80),
width: [Link],
margin: [Link](
right: [Link](5),
left: [Link](5),
),
decoration: BoxDecoration(
color: [Link],
borderRadius:
[Link]([Link](18)),
),
child: const VerticalDash(),
),
SizedBox(
height: [Link](10),
width: [Link](20),
child: DecoratedBox(
decoration: BoxDecoration(
color: [Link],
borderRadius: [Link](
topLeft:
[Link]([Link](20)),
topRight:
[Link]([Link](20)),
))),
)
],
),
),
//rest ticket
Container(
//height: [Link](100),
width: [Link](200),
decoration: BoxDecoration(
color: const Color(0xFF526799),
borderRadius: [Link](
topRight: [Link]([Link](21)),
bottomRight:
[Link]([Link](21)))),
padding: [Link]([Link](10)),
child: Row(
mainAxisAlignment: [Link],
children: [
Column(
children: [
Row(
mainAxisAlignment: [Link],
children: [
Container(
height: [Link](30),
width: [Link](30),
decoration: BoxDecoration(
borderRadius: [Link](
[Link](8)),
color: [Link],
border:
[Link](color: [Link].shade300),
image: DecorationImage(
image: AssetImage(
"assets/images/$
{[Link]['vlogo']}"))),
),
Gap([Link](5)),
Column(
crossAxisAlignment: [Link],
children: [
Text(
"${[Link]['vname']}",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: [Link]),
),
Gap([Link](3)),
Text(
"${[Link]['vinfo']}",
style: TextStyle(
color: [Link],
fontSize: 7,
fontWeight: FontWeight.w400),
),
],
)
],
),
Gap([Link](30)),
Row(
mainAxisAlignment: [Link],
children: [
Icon(
[Link],
color: [Link].shade400,
size: 15.0,
),
Gap([Link](2)),
Text(
"${[Link]['vpts']} pts",
style: [Link](
color: [Link],
fontWeight: FontWeight.w600),
),
Gap([Link](40)),
GestureDetector(
onTap: _redeemPoints,
child: Container(
decoration: BoxDecoration(
borderRadius: [Link](
[Link](10)),
color: [Link],
border: [Link](
color: [Link])),
padding: const [Link](
horizontal: 3, vertical: 3),
child: const Text(" Use Now ",
style: TextStyle(
color: [Link],
fontWeight: FontWeight.w800,
fontSize: 10))),
),
])
/* Gap([Link](30)),
Row(
mainAxisAlignment: [Link],
children: [
Icon(
[Link],
color: [Link].shade400,
size: 15.0,
),
Gap([Link](2)),
Text(
"${[Link]['vpts']} pts",
style: [Link](
color: [Link],
fontWeight: FontWeight.w600),
),
Gap([Link](60)),
SizedBox(
height: [Link](20),
width: [Link](50),
child: ElevatedButton(
onPressed: () {
// add your onPressed logic here
},
style: [Link](
shape: RoundedRectangleBorder(
borderRadius: [Link](
[Link](10)),
side: const BorderSide(
color: [Link]),
),
backgroundColor: [Link],
),
child: const Text(
"Get",
textAlign: [Link],
style: TextStyle(
color: [Link],
fontWeight: FontWeight.w600,
fontSize: 10,
),
),
),
),
],
) */
],
)
],
),
)
],
)),
),
);
}
}