0% found this document useful (0 votes)
23 views

Import 'Packagefluttermaterial - Dart

Uploaded by

Akia Aloivag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Import 'Packagefluttermaterial - Dart

Uploaded by

Akia Aloivag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

import 'package:flutter/material.

dart';
import 'package:gap/gap.dart';
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 this.vouch, this.onRedeem})
: super(key: key);

@override
_VoucherState createState() => _VoucherState();
}

class _VoucherState extends State<Voucher> {


final FirebaseAuth auth = FirebaseAuth.instance;
final FirebaseFirestore firestore = FirebaseFirestore.instance;

Future<void> _redeemPoints() async {


final currentUser = auth.currentUser;
if (currentUser != null) {
String uid = currentUser.uid;
try {
DocumentSnapshot docSnapshot =
await firestore.collection('Users').doc(uid).get();
// Access the 'qrData' field from the document snapshot
if (docSnapshot.exists) {
int garpoPoints = docSnapshot.get('Points');
int voucherPoints = widget.vouch['vpts'];
if (garpoPoints >= voucherPoints) {
await firestore.collection('Users').doc(uid).update({
'Points': garpoPoints - voucherPoints,
});
widget.onRedeem?.call(voucherPoints);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.check_circle, color: Colors.green),
SizedBox(width: 10),
Text('Successfully Redeemed',
style: TextStyle(color: Colors.white)),
],
),
backgroundColor: Colors.black,
behavior: SnackBarBehavior.floating,
duration: Duration(seconds: 3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
margin: EdgeInsets.all(20),
elevation: 5,
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.cancel, color: Colors.red),
SizedBox(width: 10),
Text('Insufficient Points!',
style: TextStyle(color: Colors.white)),
],
),
backgroundColor: Colors.black,
behavior: SnackBarBehavior.floating,
duration: Duration(seconds: 3),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
margin: EdgeInsets.all(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 = AppLayout.getSize(context);
return SizedBox(
width: size.width * 0.85,
height: AppLayout.getHeight(105),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
margin: EdgeInsets.only(
right: AppLayout.getWidth(10), bottom: AppLayout.getHeight(5)),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
//P200off
Container(
width: AppLayout.getWidth(88),
decoration: BoxDecoration(
color: const Color(0xFF526799),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(AppLayout.getHeight(21)),
bottomLeft: Radius.circular(AppLayout.getWidth(21))),
),
padding: EdgeInsets.all(AppLayout.getHeight(12)),
child: Row(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichText(
text: TextSpan(
style: Styles.headLineStyle2
.copyWith(color: Colors.white),
//style: DefaultTextStyle.of(context.style),
children: <TextSpan>[
const TextSpan(text: "₱"),
TextSpan(
text: "${widget.vouch['vworth']}",
style: Styles.headLineStyle1
.copyWith(color: Colors.white)),
])),
Gap(AppLayout.getHeight(3)),
Text(
"Available until",
style: Styles.headLineStyle6
.copyWith(color: Colors.white, fontSize: 7),
),
Text(
"${widget.vouch['vexpire']}",
style: Styles.headLineStyle6
.copyWith(color: Colors.white, fontSize: 7),
),
],
)
],
),
),

//lines
Container(
width: AppLayout.getWidth(15),
//padding: EdgeInsets.all(AppLayout.getHeight(6)),
color: const Color(0xFF526799), //const Color (0xFFF37B67),
child: Column(
children: [
SizedBox(
height: AppLayout.getHeight(10),
width: AppLayout.getWidth(20),
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomRight:
Radius.circular(AppLayout.getWidth(20)),
bottomLeft:
Radius.circular(AppLayout.getWidth(20)),
))),
),
Container(
height: AppLayout.getHeight(80),
width: double.infinity,
margin: EdgeInsets.only(
right: AppLayout.getWidth(5),
left: AppLayout.getWidth(5),
),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius:
BorderRadius.circular(AppLayout.getHeight(18)),
),
child: const VerticalDash(),
),
SizedBox(
height: AppLayout.getHeight(10),
width: AppLayout.getWidth(20),
child: DecoratedBox(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft:
Radius.circular(AppLayout.getWidth(20)),
topRight:
Radius.circular(AppLayout.getWidth(20)),
))),
)
],
),
),

//rest ticket
Container(
//height: AppLayout.getHeight(100),
width: AppLayout.getWidth(200),
decoration: BoxDecoration(
color: const Color(0xFF526799),
borderRadius: BorderRadius.only(
topRight: Radius.circular(AppLayout.getHeight(21)),
bottomRight:
Radius.circular(AppLayout.getWidth(21)))),
padding: EdgeInsets.all(AppLayout.getHeight(10)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: AppLayout.getHeight(30),
width: AppLayout.getHeight(30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
AppLayout.getHeight(8)),
color: Colors.white,
border:
Border.all(color: Colors.grey.shade300),
image: DecorationImage(
image: AssetImage(
"assets/images/$
{widget.vouch['vlogo']}"))),
),
Gap(AppLayout.getWidth(5)),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${widget.vouch['vname']}",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
),
Gap(AppLayout.getHeight(3)),
Text(
"${widget.vouch['vinfo']}",
style: TextStyle(
color: Colors.white,
fontSize: 7,
fontWeight: FontWeight.w400),
),
],
)
],
),
Gap(AppLayout.getWidth(30)),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
Icons.stars,
color: Colors.lightBlueAccent.shade400,
size: 15.0,
),
Gap(AppLayout.getWidth(2)),
Text(
"${widget.vouch['vpts']} pts",
style: Styles.headLineStyle6.copyWith(
color: Colors.white,
fontWeight: FontWeight.w600),
),
Gap(AppLayout.getWidth(40)),
GestureDetector(
onTap: _redeemPoints,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
AppLayout.getHeight(10)),
color: Colors.blueAccent,
border: Border.all(
color: Colors.lightBlueAccent)),
padding: const EdgeInsets.symmetric(
horizontal: 3, vertical: 3),
child: const Text(" Use Now ",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w800,
fontSize: 10))),
),
])

/* Gap(AppLayout.getHeight(30)),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
Icons.stars,
color: Colors.lightBlueAccent.shade400,
size: 15.0,
),
Gap(AppLayout.getWidth(2)),
Text(
"${widget.vouch['vpts']} pts",
style: Styles.headLineStyle6.copyWith(
color: Colors.white,
fontWeight: FontWeight.w600),
),
Gap(AppLayout.getWidth(60)),
SizedBox(
height: AppLayout.getHeight(20),
width: AppLayout.getWidth(50),
child: ElevatedButton(
onPressed: () {
// add your onPressed logic here
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
AppLayout.getHeight(10)),
side: const BorderSide(
color: Colors.lightBlueAccent),
),
backgroundColor: Colors.blueAccent,
),
child: const Text(
"Get",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 10,
),
),
),
),
],
) */
],
)
],
),
)
],
)),
),
);
}
}

You might also like