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

@@ -1010,7 +1010,7 @@
"languageVersion": "3.4"
}
],
"generated": "2025-02-08T20:21:28.051863Z",
"generated": "2025-02-09T21:06:34.160787Z",
"generator": "pub",
"generatorVersion": "3.5.3",
"flutterRoot": "file:///Users/apple/Documents/development/flutter",

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
import Flutter
import UIKit
@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,

View File

@@ -28,6 +28,10 @@ class APIURL {
static const String paymentOrder = "${BASE_URL}payment/initiate";
static const String paymentCODOrder = "${BASE_URL}orders";
static const String myOrder = "${BASE_URL}orders/my-orders";
static const String offerCoupon = "${BASE_URL}coupons";
static const String applyCoupon = "${BASE_URL}coupons/validate";
static const String forgetPassword = "${BASE_URL}auth/forgot-password/vendor";
static const String verifyForgetPassword =

View File

@@ -82,10 +82,14 @@ class MyRoutes {
),
animatedGoRoute(
path: COUPONSSCREEN,
name: COUPONSSCREEN,
pageBuilder: (context, state) => CouponsScreen(),
),
path: COUPONSSCREEN,
name: COUPONSSCREEN,
pageBuilder: (context, state) {
final id = state.extra as String;
return CouponsScreen(
cartId: id,
);
}),
animatedGoRoute(
path: ADDRESSS,
name: ADDRESSS,

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,165 @@
// To parse this JSON data, do
//
// final couponData = couponDataFromJson(jsondynamic);
import 'dart:convert';
CouponDataModel couponDataFromJson(dynamic str) => CouponDataModel.fromJson(json.decode(str));
dynamic couponDataToJson(CouponDataModel data) => json.encode(data.toJson());
class CouponDataModel {
List<CouponDatum>? data;
int? total;
int? page;
int? limit;
CouponDataModel({
this.data,
this.total,
this.page,
this.limit,
});
factory CouponDataModel.fromJson(Map<dynamic, dynamic> json) => CouponDataModel(
data: List<CouponDatum>.from(json["data"].map((x) => CouponDatum.fromJson(x))),
total: json["total"],
page: json["page"],
limit: json["limit"],
);
Map<dynamic, dynamic> toJson() => {
"data": List<dynamic>.from(data!.map((x) => x.toJson())),
"total": total,
"page": page,
"limit": limit,
};
}
class CouponDatum {
dynamic id;
dynamic code;
dynamic type;
dynamic discountValue;
dynamic maxDiscountAmount;
dynamic minPurchaseAmount;
DateTime? startDate;
DateTime? endDate;
int? totalUsageLimit;
int? perUserUsageLimit;
dynamic applicability;
dynamic status;
dynamic description;
dynamic terms;
int? buyQuantity;
int? getQuantity;
List<dynamic>? applicableUserRoles;
int? totalUsageCount;
bool? isActive;
dynamic createdBy;
DateTime? createdAt;
DateTime? updatedAt;
List<dynamic>? applicableStores;
List<dynamic>? applicableCategories;
List<dynamic>? applicableProducts;
List<dynamic>? usages;
List<dynamic>? applicableStoreIds;
List<dynamic>? applicableCategoryIds;
List<dynamic>? applicableProductIds;
CouponDatum({
this.id,
this.code,
this.type,
this.discountValue,
this.maxDiscountAmount,
this.minPurchaseAmount,
this.startDate,
this.endDate,
this.totalUsageLimit,
this.perUserUsageLimit,
this.applicability,
this.status,
this.description,
this.terms,
this.buyQuantity,
this.getQuantity,
this.applicableUserRoles,
this.totalUsageCount,
this.isActive,
this.createdBy,
this.createdAt,
this.updatedAt,
this.applicableStores,
this.applicableCategories,
this.applicableProducts,
this.usages,
this.applicableStoreIds,
this.applicableCategoryIds,
this.applicableProductIds,
});
factory CouponDatum.fromJson(Map<dynamic, dynamic> json) => CouponDatum(
id: json["id"],
code: json["code"],
type: json["type"],
discountValue: json["discountValue"],
maxDiscountAmount: json["maxDiscountAmount"],
minPurchaseAmount: json["minPurchaseAmount"],
startDate: DateTime.parse(json["startDate"]),
endDate: DateTime.parse(json["endDate"]),
totalUsageLimit: json["totalUsageLimit"],
perUserUsageLimit: json["perUserUsageLimit"],
applicability: json["applicability"],
status: json["status"],
description: json["description"],
terms: json["terms"],
buyQuantity: json["buyQuantity"],
getQuantity: json["getQuantity"],
applicableUserRoles: List<dynamic>.from(json["applicableUserRoles"].map((x) => x)),
totalUsageCount: json["totalUsageCount"],
isActive: json["isActive"],
createdBy: json["createdBy"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
applicableStores: List<dynamic>.from(json["applicableStores"].map((x) => x)),
applicableCategories: List<dynamic>.from(json["applicableCategories"].map((x) => x)),
applicableProducts: List<dynamic>.from(json["applicableProducts"].map((x) => x)),
usages: List<dynamic>.from(json["usages"].map((x) => x)),
applicableStoreIds: List<dynamic>.from(json["applicableStoreIds"].map((x) => x)),
applicableCategoryIds: List<dynamic>.from(json["applicableCategoryIds"].map((x) => x)),
applicableProductIds: List<dynamic>.from(json["applicableProductIds"].map((x) => x)),
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"code": code,
"type": type,
"discountValue": discountValue,
"maxDiscountAmount": maxDiscountAmount,
"minPurchaseAmount": minPurchaseAmount,
"startDate": startDate,
"endDate": endDate,
"totalUsageLimit": totalUsageLimit,
"perUserUsageLimit": perUserUsageLimit,
"applicability": applicability,
"status": status,
"description": description,
"terms": terms,
"buyQuantity": buyQuantity,
"getQuantity": getQuantity,
"applicableUserRoles": List<dynamic>.from(applicableUserRoles!.map((x) => x)),
"totalUsageCount": totalUsageCount,
"isActive": isActive,
"createdBy": createdBy,
"createdAt": createdAt,
"updatedAt": updatedAt,
"applicableStores": List<dynamic>.from(applicableStores!.map((x) => x)),
"applicableCategories": List<dynamic>.from(applicableCategories!.map((x) => x)),
"applicableProducts": List<dynamic>.from(applicableProducts!.map((x) => x)),
"usages": List<dynamic>.from(usages!.map((x) => x)),
"applicableStoreIds": List<dynamic>.from(applicableStoreIds!.map((x) => x)),
"applicableCategoryIds": List<dynamic>.from(applicableCategoryIds!.map((x) => x)),
"applicableProductIds": List<dynamic>.from(applicableProductIds!.map((x) => x)),
};
}

View File

@@ -0,0 +1,69 @@
// To parse this JSON data, do
//
// final couponResponse = couponResponseFromJson(jsonString);
import 'dart:convert';
CouponResponse couponResponseFromJson(String str) => CouponResponse.fromJson(json.decode(str));
String couponResponseToJson(CouponResponse data) => json.encode(data.toJson());
class CouponResponse {
bool? isValid;
String? originalPrice;
int? discountAmount;
int? finalPrice;
String? message;
CouponDetails? couponDetails;
CouponResponse({
this.isValid,
this.originalPrice,
this.discountAmount,
this.finalPrice,
this.message,
this.couponDetails,
});
factory CouponResponse.fromJson(Map<String, dynamic> json) => CouponResponse(
isValid: json["isValid"],
originalPrice: json["originalPrice"],
discountAmount: json["discountAmount"],
finalPrice: json["finalPrice"],
message: json["message"],
couponDetails: CouponDetails.fromJson(json["couponDetails"]),
);
Map<String, dynamic> toJson() => {
"isValid": isValid,
"originalPrice": originalPrice,
"discountAmount": discountAmount,
"finalPrice": finalPrice,
"message": message,
"couponDetails": couponDetails!.toJson(),
};
}
class CouponDetails {
String? code;
String? type;
String? discountValue;
CouponDetails({
this.code,
this.type,
this.discountValue,
});
factory CouponDetails.fromJson(Map<String, dynamic> json) => CouponDetails(
code: json["code"],
type: json["type"],
discountValue: json["discountValue"],
);
Map<String, dynamic> toJson() => {
"code": code,
"type": type,
"discountValue": discountValue,
};
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,8 @@ import 'package:grocery_app/src/core/network_services/service_locator.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
import 'package:grocery_app/src/data/address.dart';
import 'package:grocery_app/src/data/all_cart_items.dart';
import 'package:grocery_app/src/data/coupon_model.dart';
import 'package:grocery_app/src/data/coupon_response.dart';
import 'package:grocery_app/src/logic/repo/product_repo.dart';
import 'package:grocery_app/src/ui/payment/payment_webView.dart';
import 'package:grocery_app/utils/extensions/extensions.dart';
@@ -125,6 +127,16 @@ class AddtocartProvider extends ChangeNotifier {
}
}
double _totalPrice = 0.0;
double _grandPrice = 0.0;
double _discount = 0.0;
double get totalPrice => _totalPrice;
double get grandPrice => _grandPrice;
double get discount => _discount;
final _homeRepo = getIt<ProductRepo>();
AllCartItems allitem = AllCartItems();
@@ -144,6 +156,9 @@ class AddtocartProvider extends ChangeNotifier {
},
(response) {
allitem = response!;
_totalPrice = double.parse(response.subtotal.toString());
_grandPrice = double.parse(response.subtotal.toString());
isLoaddcartItem = false;
notifyListeners();
},
@@ -154,36 +169,118 @@ class AddtocartProvider extends ChangeNotifier {
notifyListeners();
}
}
//////////////////////////////////// coupon ////////////////////////////
bool iscouponLoading = true;
CouponDataModel couponDataModel = CouponDataModel();
Future<void> offerCoupon(BuildContext context) async {
iscouponLoading = true;
notifyListeners();
var data = {};
try {
var result = await _homeRepo.offerCoupon(data);
return result.fold(
(error) {
iscouponLoading = false;
notifyListeners();
},
(response) {
couponDataModel = response!;
iscouponLoading = false;
notifyListeners();
},
);
} catch (e) {
iscouponLoading = false;
notifyListeners();
}
}
bool isCouponApply = false;
CouponResponse couponResponse = CouponResponse();
String _couponId = '';
String get couponId => _couponId;
Future<bool> applyCoupon(
BuildContext context, String cartId, String couponscode, id) async {
context.showLoader(show: true);
isCouponApply = true;
notifyListeners();
var data = {"couponCode": couponscode, "cartId": cartId};
try {
var result = await _homeRepo.applyCoupon(data);
return result.fold(
(error) {
context.showLoader(show: false);
isCouponApply = false;
Fluttertoast.showToast(
msg: "Coupon Code invalid!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 14.0,
);
notifyListeners();
return false;
},
(response) {
if (response != null) {
couponResponse = response;
_couponId = id;
_grandPrice = double.parse(response.finalPrice.toString());
_discount = double.parse(response.discountAmount.toString());
context.showLoader(show: false);
isCouponApply = false;
notifyListeners();
return true;
} else {
context.showLoader(show: false);
isCouponApply = false;
notifyListeners();
return false;
}
},
);
} catch (e) {
context.showLoader(show: false);
Fluttertoast.showToast(
msg: "Coupon Code invalid!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 14.0,
);
isCouponApply = false;
notifyListeners();
return false; // Return false on exception
}
}
///////////////////////////////////orderPaymnet///////////////////////////
bool ispaymentLoader = false;
Future<void> orderPaymnet(
BuildContext context,
double amount,
String currency,
double originalAmount,
String name,
String phone,
String email,
String userI,
String cartId,
String addressId,
String remarks,
String couponId,
) async {
ispaymentLoader = true;
notifyListeners();
var data = {
"amount": amount,
"currency": currency,
"originalAmount": amount,
"name": name,
"phone": phone,
"email": email,
"userId": userI,
"cartId": cartId,
"amount": originalAmount,
"addressId": addressId,
"remarks": remarks
"cartId": cartId,
"couponId": couponId
};
try {
@@ -221,16 +318,13 @@ class AddtocartProvider extends ChangeNotifier {
BuildContext context,
double subtotal,
double deliverCharge,
double discountPrice,
double grandTotal,
String couponId,
String addressId,
) async {
print("sdkjfhgkjdfhgjkldfkjghkdf");
ispaymentLoader = true;
notifyListeners();
var data;
if (couponId != '00') {
if (couponId.isNotEmpty) {
data = {
"addressId": addressId,
"paymentMethod": "COD",
@@ -238,12 +332,10 @@ class AddtocartProvider extends ChangeNotifier {
"orderStatus": "PENDING",
"subtotal": subtotal,
"deliveryCharge": deliverCharge,
"discount": discountPrice,
"grandTotal": grandTotal,
"transactionId": "phonepe_transaction_123",
"couponId": couponId
};
} else {
print("skfdjdsjfg");
data = {
"addressId": addressId,
"paymentMethod": "COD",
@@ -251,8 +343,6 @@ class AddtocartProvider extends ChangeNotifier {
"orderStatus": "PENDING",
"subtotal": subtotal,
"deliveryCharge": deliverCharge,
"discount": discountPrice,
"grandTotal": grandTotal,
};
}

View File

@@ -254,15 +254,16 @@ class ProductProvider extends ChangeNotifier {
}
}
void toggleWishlist1(String productId) {
for (var product in products) {
if (product.id == productId) {
product.isInWishlist = !product.isInWishlist; // Toggle value
notifyListeners(); // Refresh UI
break;
}
}
}
// void toggleWishlist1(String productId)
// {
// for (var product in products) {
// if (product.id == productId) {
// product.isInWishlist = !product.isInWishlist; // Toggle value
// notifyListeners(); // Refresh UI
// break;
// }
// }
// }
// Future<bool> addToCart(BuildContext context, String productId) async
// {

View File

@@ -13,6 +13,8 @@ import 'package:grocery_app/src/data/banners.dart';
import 'package:grocery_app/src/data/best_dealProduct.dart';
import 'package:grocery_app/src/data/check_pin_response.dart';
import 'package:grocery_app/src/data/cod_order_response.dart';
import 'package:grocery_app/src/data/coupon_model.dart';
import 'package:grocery_app/src/data/coupon_response.dart';
import 'package:grocery_app/src/data/login_response.dart';
import 'package:grocery_app/src/data/order_paymnet.dart';
import 'package:grocery_app/src/data/product_category.dart';
@@ -53,7 +55,7 @@ class ProductRepo {
var response = await _productService.getProductDetails(data, id);
ProductDetailsData loginResponse =
productDetailsdataFromJson(response.toString());
productDetailsDataFromJson(response.toString());
final String model = response.toString();
@@ -115,13 +117,11 @@ class ProductRepo {
}
}
FutureResult<CodOrderResponse> paymentCODOrder(data) async {
FutureResult<CodOrderResponse> paymentCODOrder(data) async {
try {
var response = await _productService.paymentCODOrder(data);
CodOrderResponse productCategory = codOrderResponseFromJson(response.toString());
CodOrderResponse productCategory =
codOrderResponseFromJson(response.toString());
return right(productCategory);
} on DioException catch (e) {
@@ -130,11 +130,6 @@ class ProductRepo {
}
}
FutureResult<List<Product>> similarProduct(
data, BuildContext context, id) async {
try {
@@ -165,6 +160,34 @@ class ProductRepo {
}
}
FutureResult<CouponDataModel> offerCoupon(data) async {
try {
var response = await _productService.offerCoupon(data);
CouponDataModel couponmodel = couponDataFromJson(response.toString());
return right(couponmodel);
} on DioException catch (e) {
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
FutureResult<CouponResponse> applyCoupon(data) async {
try {
var response = await _productService.applyCoupon(data);
CouponResponse couponresponse = couponResponseFromJson(response.toString());
return right(couponresponse);
} on DioException catch (e) {
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
FutureResult<AddressResponse> getAddress(data) async {
try {
var response = await _productService.getAddress(data);

View File

@@ -80,6 +80,22 @@ class ProductService extends ApiService {
return response;
}
Future offerCoupon(data) async {
var response = await api.get(APIURL.offerCoupon, data: jsonEncode(data));
return response;
}
Future applyCoupon(data) async {
var response = await api.post(APIURL.applyCoupon, data: jsonEncode(data));
return response;
}
Future checkPin(data, pin) async {
var response = await api.get(APIURL.checkPin + pin, data: jsonEncode(data));

View File

@@ -184,6 +184,7 @@ class _BestDealScreenState extends State<BestDealScreen> {
} else if (provider.bestdeal.isEmpty) {
return Center(child: Text('No products available'));
} else {
print("kjhfgjkdfkjghdhjfgk ${provider.bestdeal.first.additionalInfo}");
return Padding(
padding: const EdgeInsets.all(15),
child: GridView.builder(
@@ -273,8 +274,6 @@ class _BestDealScreenState extends State<BestDealScreen> {
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 16),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.005),
Text(
bestdealproduct.unit ?? "",
textAlign: TextAlign.left,
@@ -285,7 +284,7 @@ class _BestDealScreenState extends State<BestDealScreen> {
12,
),
),
if (provider.productDetails.data!.quantity > 0)
if (bestdealproduct!.quantity > 0)
Text("In Stock ",
style:
TextStyle(color: Colors.green, fontSize: 14)),
@@ -381,142 +380,6 @@ class _BestDealScreenState extends State<BestDealScreen> {
},
),
);
// Padding(
// padding: const EdgeInsets.all(15),
// child: GridView.builder(
// itemCount: provider.bestdeal.length,
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
// crossAxisCount: 2,
// childAspectRatio: MediaQuery.of(context).size.width /
// (MediaQuery.of(context).size.height / 1.5),
// crossAxisSpacing: 10,
// mainAxisSpacing: 10),
// itemBuilder: (context, index) {
// var bestdealproduct = provider.bestdeal[index];
// return Container(
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15),
// boxShadow: [
// BoxShadow(
// color: Colors.grey.withOpacity(0.1),
// blurRadius: 1,
// offset: const Offset(5, 5),
// ),
// ]),
// child: Padding(
// padding: const EdgeInsets.all(5),
// child:
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Container(
// height: 100.h,
// width: MediaQuery.sizeOf(context).width,
// // width: 150,
// decoration: BoxDecoration(
// color: APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(15)),
// child: Stack(
// alignment: Alignment.center,
// children: [
// AppNetworkImage(
// height: 90.h,
// width: 140,
// imageUrl:
// bestdealproduct.productImages?.first.url ??
// "",
// backGroundColor: Colors.transparent),
// Positioned(
// right: 5,
// top: 5,
// child: Icon(Icons.favorite_border))
// ],
// ),
// ),
// Text(
// bestdealproduct.name ?? "",
// textAlign: TextAlign.left,
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(APPCOLOR.balck1A1A1A, 16),
// ),
// const SizedBox(
// height: 5,
// ),
// Text(
// bestdealproduct.unit ?? "",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(
// Colors.grey.withOpacity(0.8), 12),
// ),
// const SizedBox(
// height: 3,
// ),
// SizedBox(
// height: MediaQuery.of(context).size.height * 0.005,
// ),
// Spacer(),
// Row(
// children: [
// Row(
// children: [
// Text(
// "\$${bestdealproduct.discountPrice ?? ""} ",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customSemiBold(Colors.black, 12),
// ),
// Text(
// "\$${bestdealproduct.basePrice ?? ""}",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context
// .customMedium(
// Colors.grey.withOpacity(0.8),
// 12,
// )
// .copyWith(
// decoration: TextDecoration.lineThrough,
// ),
// ),
// ],
// ),
// const Spacer(),
// Align(
// alignment: Alignment.centerRight,
// child: Container(
// height:
// MediaQuery.of(context).size.height * 0.035,
// width: MediaQuery.of(context).size.width * 0.1,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Add',
// style:
// context.customRegular(Colors.white, 12),
// ),
// ),
// ),
// ),
// ],
// ),
// ],
// ),
// ),
// );
// },
// ),
// );
}
});
}

View File

@@ -153,8 +153,6 @@ class _BottomBarState extends State<BottomBarWidget> {
],
),
),
);
}
}

View File

@@ -9,34 +9,33 @@ import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:provider/provider.dart';
class CardCheckoutScreen extends StatefulWidget {
double amount;
String currency;
// double amount;
// String currency;
double originalAmount;
String name;
String phone;
String email;
String userId;
// String name;
// String phone;
// String email;
// String userId;
String cartId;
String addressId;
String remarks;
// String remarks;
double deliverCharge;
double discountPrice;
String? couponId;
CardCheckoutScreen(
{super.key,
required this.amount,
required this.currency,
// required this.amount,
// required this.currency,
required this.originalAmount,
required this.name,
required this.phone,
required this.email,
required this.userId,
// required this.name,
// required this.phone,
// required this.email,
// required this.userId,
required this.cartId,
required this.addressId,
required this.remarks,
// required this.remarks,
required this.deliverCharge,
required this.discountPrice,
this.couponId});
@override
@@ -88,28 +87,19 @@ class _CardCheckoutScreenState extends State<CardCheckoutScreen> {
child: InkWell(
onTap: () {
if (paymentProvider.selectedPaymentMethod == "Online") {
print("dsjfkhkdfhgdkfghdfg");
paymentProvider.orderPaymnet(
context,
widget.amount,
widget.currency,
widget.originalAmount,
widget.name,
widget.phone,
widget.email,
widget.userId,
widget.cartId,
widget.addressId,
widget.remarks);
widget.couponId!);
} else {
print("ldksjfgkljdfghljkfdg");
paymentProvider.paymentCODOrder(
context,
widget.amount,
widget.deliverCharge,
widget.discountPrice,
widget.originalAmount,
// widget.couponId!,
'00',
widget.deliverCharge,
widget.couponId!,
widget.addressId,
);
}

View File

@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
@@ -37,13 +37,15 @@ class Mycart extends StatefulWidget {
class _MycartState extends State<Mycart> {
@override
void initState() {
Provider.of<AddtocartProvider>(context, listen: false)
.getItemCards(context);
Provider.of<AddtocartProvider>(context, listen: false)
.getCurrentLocation(context);
Provider.of<AddtocartProvider>(context, listen: false).getAddress(context);
Future.microtask(() {
final addToCartProvider =
Provider.of<AddtocartProvider>(context, listen: false);
addToCartProvider.getItemCards(context);
addToCartProvider.offerCoupon(context);
addToCartProvider.getCurrentLocation(context);
addToCartProvider.getAddress(context);
});
super.initState();
}
@@ -165,38 +167,13 @@ class _MycartState extends State<Mycart> {
),
child: Center(
child: Text(
"${calculateDiscountPercentage(double.parse(provider.productDetails.data!.basePrice), double.parse(provider.productDetails.data!.discountPrice))}% OFF",
"${calculateDiscountPercentage(double.parse(bestdealproduct!.basePrice), double.parse(bestdealproduct!.discountPrice))}% OFF",
style: TextStyle(
color: Colors.white,
fontSize: 12)),
),
),
)
// Positioned(
// right: 5,
// top: 5,
// child: InkWell(
// onTap: () async {
// if (await SharedPrefUtils.getToken() !=
// null) {
// provider.toggleWishlist(
// context, bestdealproduct.id!);
// } else {
// context.push(MyRoutes.LOGIN);
// }
// },
// child: Icon(
// provider.wishlist
// .contains(bestdealproduct.id)
// ? Icons.favorite
// : Icons.favorite_border,
// color: provider.wishlist
// .contains(bestdealproduct.id)
// ? Colors.red
// : Colors.grey,
// ),
// ),
// ),
],
),
),
@@ -749,7 +726,6 @@ class _MycartState extends State<Mycart> {
),
));
} else {
print("kldjhgjkhfgjkh ");
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -759,18 +735,29 @@ class _MycartState extends State<Mycart> {
style: TextStyle(fontWeight: FontWeight.bold)),
trailing: Icon(Icons.arrow_forward_ios),
onTap: () {
context.push(MyRoutes.COUPONSSCREEN);
if (provider.couponDataModel.data!.isNotEmpty) {
context.push(MyRoutes.COUPONSSCREEN,
extra: provider.allitem.id);
} else {
Fluttertoast.showToast(
msg: "Coupon's not available !",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 14.0,
);
}
},
),
SummaryRow(
label: 'Item Total Price',
value: '\$${provider.allitem.subtotal}'),
SummaryRow(label: 'Discount', value: '0.0'),
label: 'Item Total Price', value: '\$${provider.totalPrice}'),
SummaryRow(label: 'Discount', value: "${provider.discount}"),
SummaryRow(label: 'Delivery Free', value: 'Free', isGreen: true),
Divider(),
SummaryRow(
label: 'Grand Total',
value: '\$${provider.allitem.subtotal}',
value: '\$${provider.grandPrice}',
isBold: true),
ListTile(
leading: Icon(Icons.home, color: Colors.green),
@@ -991,32 +978,40 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
SizedBox(height: 16),
Consumer<AddtocartProvider>(
builder: (context, paymentProvider, child) {
print(
"prxvsvxvice ${double.parse(paymentProvider.allitem.subtotal.toString())} ${paymentProvider.selecteUserName} ${paymentProvider.selectedAddress} ${paymentProvider.selecteEmail} ${paymentProvider.selecteUserPhone}");
return ElevatedButton.icon(
onPressed: () {
Navigator.pop(context);
Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return CardCheckoutScreen(
amount: double.parse(
paymentProvider.allitem.subtotal.toString()),
currency: "INR",
originalAmount: double.parse(
paymentProvider.allitem.subtotal.toString()),
name: paymentProvider.selecteUserName,
phone: paymentProvider.selecteUserPhone,
email: paymentProvider.selecteEmail,
userId: paymentProvider.allitem.userId!,
cartId: paymentProvider.allitem.id!,
addressId: paymentProvider.selectedAddress,
remarks: paymentProvider.selecteUserName,
deliverCharge: 0,
discountPrice: 0,
couponId: '',
);
},
));
if (paymentProvider.selectedAddress.isNotEmpty) {
Navigator.pop(context);
Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return CardCheckoutScreen(
// amount: double.parse(
// paymentProvider.allitem.subtotal.toString()),
// currency: "INR",
originalAmount: paymentProvider.grandPrice,
// name: paymentProvider.selecteUserName,
// phone: paymentProvider.selecteUserPhone,
// email: paymentProvider.selecteEmail,
// userId: paymentProvider.allitem.userId!,
cartId: paymentProvider.allitem.id!,
addressId: paymentProvider.selectedAddress,
// remarks: paymentProvider.selecteUserName,
deliverCharge: 0,
couponId: paymentProvider.couponId,
);
},
));
} else {
Fluttertoast.showToast(
msg: "Please add a delivery address",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 14.0,
);
}
},
label: Text(
"Continue",
@@ -1049,13 +1044,6 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
itemBuilder: (context, index) {
var address = addressProvider.addresslist[index];
// // if (addressProvider.addresslist.length == 1) {
// // addressProvider.bydefaultSetAddress(
// // address.phoneNumber, address.name, address.user!.email);
// // }
// print("sdhfjdjkfhg ${address.id} ${index}");
return Card(
elevation: 0,
shape: RoundedRectangleBorder(

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"),
)
],
)
],
),
),
);
},
),
);
}
}),
],
),
),

View File

@@ -33,10 +33,8 @@ class _MyOrderScreenState extends State<MyOrderScreen> {
height: 20,
width: 20,
child: InkWell(
onTap: ()
{
context.clearAndPush(routePath: MyRoutes.BOTTOMNAV);
onTap: () {
context.clearAndPush(routePath: MyRoutes.BOTTOMNAV);
},
child: SvgPicture.asset(
APPASSETS.back,
@@ -71,7 +69,8 @@ class _MyOrderScreenState extends State<MyOrderScreen> {
final order = orderProvider.orderList[index];
return InkWell(
onTap: () {
onTap: ()
{
context.pushNamed(MyRoutes.ORDERDETAILS, extra: order);
//context.push(MyRoutes.ORDERDETAILS);
},
@@ -155,7 +154,7 @@ class _MyOrderScreenState extends State<MyOrderScreen> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("\$" + order.grandTotal,
Text("\$" + order.subtotal,
style:
TextStyle(fontWeight: FontWeight.bold)),
Row(
@@ -185,8 +184,8 @@ class _MyOrderScreenState extends State<MyOrderScreen> {
ElevatedButton(
onPressed: () {
print("lkdhgkjdfgj");
_makePhoneCall(
order.stores!.first.vendor!.phone);
// _makePhoneCall(
// order.stores!.first.vendor!.phone);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,

View File

@@ -10,7 +10,7 @@ import 'package:gap/gap.dart';
import 'package:go_router/go_router.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
import 'package:grocery_app/src/data/allProduct_model.dart';
import 'package:grocery_app/src/data/product_details.dart';
import 'package:grocery_app/src/logic/provider/bottom_navbar_provider.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
@@ -327,62 +327,61 @@ class _ProductDetailsState extends State<ProductDetails> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text("Highlights",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold)),
Gap(2),
Expanded(
child: Container(
color: Colors.grey,
height: 0.4,
),
)
],
),
AnimatedSize(
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
if (provider.productDetails.data!.brand !=
null)
_buildText(
"Brand ",
'${provider.productDetails.data!.brand ?? ''}',
),
// if (isHilightsExpanded)
_buildText(
"Weight",
'${provider.productDetails.data!.unit ?? ""}',
if (provider.productDetails.data!.productHighlight!
.isNotEmpty) ...{
Row(
children: [
Text("Highlights",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold)),
Gap(2),
Expanded(
child: Container(
color: Colors.grey,
height: 0.4,
),
if (isHilightsExpanded)
_buildText(
"Product Type",
'${provider.productDetails.data!.productType ?? ""}',
),
],
)
],
),
AnimatedSize(
duration: Duration(milliseconds: 300),
curve: Curves.easeInOut,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: isHilightsExpanded
? provider.productDetails.data!
.productHighlight!.length
: 2,
itemBuilder: (context, index) {
final item = provider.productDetails.data!
.productHighlight![index];
return _buildText(
item.key ?? '', item.value ?? '');
},
),
),
),
),
Center(
child: TextButton(
onPressed: () {
setState(() {
isHilightsExpanded = !isHilightsExpanded;
});
},
child: Text(
isHilightsExpanded
? "View Less"
: "View More",
style: TextStyle(color: APPCOLOR.appGreen),
),
),
),
},
Center(
child: TextButton(
onPressed: () {
setState(() {
isHilightsExpanded = !isHilightsExpanded;
});
},
child: Text(
isHilightsExpanded ? "View Less" : "View More",
style: TextStyle(color: APPCOLOR.appGreen),
),
),
),
Row(
children: [
Text("Information",
@@ -419,11 +418,12 @@ class _ProductDetailsState extends State<ProductDetails> {
"Seller Address",
'${provider.productDetails.data!.store!.storeAddress ?? ""}',
),
if (isExpanded)
_buildText(
"GST Number",
'${provider.productDetails.data!.store!.gstNumber ?? ""}',
),
// if (isExpanded)
// _buildText(
// "GST Number",
// '${provider.productDetails.data!.store!.gstNumber ?? ""}',
// ),
],
),
),