169 lines
6.9 KiB
Dart
169 lines
6.9 KiB
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:provider/provider.dart';
|
|
|
|
class CouponsScreen extends StatelessWidget {
|
|
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,
|
|
title: Text("Coupons"),
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back_ios),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
),
|
|
body: Padding(
|
|
padding: EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: [
|
|
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),
|
|
),
|
|
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),
|
|
),
|
|
),
|
|
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"),
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|