complete category issue

This commit is contained in:
2025-03-20 18:21:48 +05:30
parent 7ab5c896f0
commit 6a10900f68
21 changed files with 1198 additions and 420 deletions

View File

@@ -1,6 +1,11 @@
import 'dart:math';
import 'dart:ui';
import 'package:blur/blur.dart';
import 'package:flutter/material.dart';
import 'package:grocery_app/src/logic/provider/addTocart_provider.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class CouponsScreen extends StatelessWidget {
@@ -11,6 +16,7 @@ class CouponsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
Provider.of<AddtocartProvider>(context, listen: false).offerCoupon(context);
print("kldfjgdfkljgdf ${cartId}");
return Scaffold(
appBar: AppBar(
@@ -43,15 +49,12 @@ class CouponsScreen extends StatelessWidget {
child: ElevatedButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
// var status = await provider.applyCoupon(
// context,
// cartId,
// inpucode.text,
// );
var status = await provider.applyCoupon(
context, cartId, inpucode.text, '');
// if (status) {
// Navigator.pop(context);
// }
if (status) {
Navigator.pop(context);
}
}
},
style: ElevatedButton.styleFrom(
@@ -84,78 +87,266 @@ class CouponsScreen extends StatelessWidget {
return Expanded(
child: ListView.builder(
itemCount: provider.couponDataModel.data!.length,
itemBuilder: (context, index)
{
itemBuilder: (context, index) {
final coupon = provider.couponDataModel.data![index];
DateTime couponEndDate =
DateTime.parse(coupon.endDate.toString()).toUtc();
DateTime now = DateTime.now().toUtc();
bool isCouponValid = now.isBefore(couponEndDate);
print(
"Coupon Expiry: ${coupon.endDate} ${coupon.imageUrl}| Current UTC Time: $now | Valid: $isCouponValid");
return Card(
color: Colors.white,
color: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
elevation: 4,
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Stack(
children: [
Text(
coupon.description!,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
// Background Image
Positioned.fill(
child: Image.network(
coupon.imageUrl,
fit: BoxFit.cover,
),
),
SizedBox(height: 5),
Text(
coupon.terms!,
style: TextStyle(color: Colors.grey[600]),
),
SizedBox(height: 10),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 5),
decoration: BoxDecoration(
border: Border.all(color: Colors.green),
borderRadius: BorderRadius.circular(8),
),
child: Text(
coupon.code!,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.green,
),
),
),
ElevatedButton(
onPressed: () async {
var status = await provider.applyCoupon(
context,
cartId,
coupon.code,
coupon.id);
{
Navigator.pop(context);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
// Blur Effect
Positioned.fill(
child: BackdropFilter(
filter:
ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
color: Colors.black.withOpacity(
0.3), // Dark overlay for readability
),
),
),
// Coupon Content
Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
coupon.description ?? '',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors
.white, // Ensure contrast with background
),
),
child: Text("Apply"),
)
],
)
SizedBox(height: 5),
Row(
children: [
Text(
"Expired On : ",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors
.white, // Ensure contrast with background
),
),
Text(
DateFormat("dd-MM-yyyy").format(
DateTime.parse(
coupon.endDate.toString())),
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color:
Colors.white, // Highlight price
),
),
],
),
SizedBox(height: 5),
Text(
"${coupon.discountValue ?? ''}",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.amber, // Highlight price
),
),
SizedBox(height: 5),
Text(
coupon.terms ?? "",
style: TextStyle(color: Colors.white70),
),
SizedBox(height: 10),
// Coupon Code and Apply Button
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
// Coupon Code Box
Container(
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color:
Colors.white.withOpacity(0.2),
border:
Border.all(color: Colors.green),
borderRadius:
BorderRadius.circular(8),
),
child: Text(
coupon.code!,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
// Apply Button
ElevatedButton(
onPressed: isCouponValid
? () async {
var status = await provider
.applyCoupon(
context,
cartId,
coupon.code,
coupon.id);
if (status) {
Navigator.pop(context);
}
}
: null, // Disable button if expired
style: ElevatedButton.styleFrom(
backgroundColor: isCouponValid
? Colors.green
: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(8),
),
),
child: Text("Apply"),
),
],
),
],
),
),
],
),
),
);
// Card(
// color: Colors.transparent.withOpacity(0.4),
// // color: Color((Random().nextDouble() * 0xFFFFFF).toInt())
// // .withOpacity(0.9),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(12),
// ),
// elevation: 2,
// child: Blur(
// blur: 2.5,
// // blurColor: Theme.of(context).primaryColor,
// child: Container(
// decoration: BoxDecoration(
// image: DecorationImage(
// image: NetworkImage(
// coupon.imageUrl), // Your background image
// fit: BoxFit.cover, // Adjust as needed
// ),
// borderRadius: BorderRadius.circular(
// 12), // Match Card's border radius
// ),
// child: Padding(
// padding: EdgeInsets.all(16.0),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text(
// coupon.description ?? '',
// style: TextStyle(
// fontSize: 16,
// fontWeight: FontWeight.bold,
// ),
// ),
// Text(
// "₹" + coupon.discountValue ?? '',
// style: TextStyle(
// fontSize: 16,
// fontWeight: FontWeight.bold,
// ),
// ),
// SizedBox(height: 5),
// Text(
// coupon.terms ?? "",
// style: TextStyle(color: Colors.grey[600]),
// ),
// SizedBox(height: 10),
// Row(
// mainAxisAlignment:
// MainAxisAlignment.spaceBetween,
// children: [
// Container(
// padding: EdgeInsets.symmetric(
// horizontal: 10, vertical: 5),
// decoration: BoxDecoration(
// border:
// Border.all(color: Colors.green),
// borderRadius:
// BorderRadius.circular(8),
// ),
// child: Text(
// coupon.code!,
// style: TextStyle(
// fontWeight: FontWeight.bold,
// color: Colors.green,
// ),
// ),
// ),
// ElevatedButton(
// onPressed: isCouponValid
// ? () async {
// var status =
// await provider.applyCoupon(
// context,
// cartId,
// coupon.code,
// coupon.id);
// if (status) {
// Navigator.pop(context);
// }
// }
// : null, // Disables button if expired
// style: ElevatedButton.styleFrom(
// backgroundColor: isCouponValid
// ? Colors.green
// : Colors.grey,
// shape: RoundedRectangleBorder(
// borderRadius:
// BorderRadius.circular(8),
// ),
// ),
// child: Text("Apply"),
// )
// ],
// )
// ],
// ),
// ),
// ),
// ),
// );
},
),
);