couponApply

This commit is contained in:
2025-02-10 02:37:06 +05:30
parent 630a918307
commit b6ef70cfb6
21 changed files with 3308 additions and 1181 deletions

View File

@@ -1,26 +1,17 @@
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:provider/provider.dart';
class CouponsScreen extends StatelessWidget {
final List<Map<String, String>> coupons = [
{
"title": "Flat 10% OFF on Standard Chartered Digismart Credit Cards",
"description": "No Minimum Order Value",
"code": "DIGISMART"
},
{
"title": "Flat 10% OFF upto \$10 on HSBC Cashback Credit Card",
"description": "Total Value of Items Must be \$3 or More",
"code": "HSBC10"
},
{
"title": "Get Upto 50 OFF on Your First Payment",
"description": "Total Value of Items Must be \$10 or More",
"code": "PAYMENT50"
}
];
String cartId;
CouponsScreen({super.key, required this.cartId});
TextEditingController inpucode = TextEditingController();
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
print("kldfjgdfkljgdf ${cartId}");
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
@@ -34,99 +25,141 @@ class CouponsScreen extends StatelessWidget {
padding: EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
cursorHeight: 20,
decoration: InputDecoration(
hintText: "Enter Coupon Code",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
suffixIcon: Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
Form(
key: _formKey,
child: Consumer<AddtocartProvider>(
builder: (context, provider, child) {
return TextFormField(
controller: inpucode,
cursorHeight: 20,
readOnly: false,
decoration: InputDecoration(
hintText: "Enter Coupon Code",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text("Apply"),
),
),
),
),
SizedBox(height: 16),
Expanded(
child: ListView.builder(
itemCount: coupons.length,
itemBuilder: (context, index) {
final coupon = coupons[index];
return Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
coupon["title"]!,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
suffixIcon: Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
// var status = await provider.applyCoupon(
// context,
// cartId,
// inpucode.text,
// );
// if (status) {
// Navigator.pop(context);
// }
}
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
SizedBox(height: 5),
Text(
coupon["description"]!,
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: () {
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text("Apply"),
)
],
)
],
child: Text("Apply"),
),
),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return "Please enter a coupon code";
}
return null;
},
);
},
),
),
SizedBox(height: 16),
Consumer<AddtocartProvider>(builder: (context, provider, child) {
if (provider.iscouponLoading) {
return Center(child: CircularProgressIndicator());
} else if (provider.couponDataModel.data!.isEmpty) {
return SizedBox.shrink();
} else {
return Expanded(
child: ListView.builder(
itemCount: provider.couponDataModel.data!.length,
itemBuilder: (context, index) {
final coupon = provider.couponDataModel.data![index];
return Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 2,
child: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
coupon.description!,
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: () 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),
),
),
child: Text("Apply"),
)
],
)
],
),
),
);
},
),
);
}
}),
],
),
),