orderpayment

This commit is contained in:
2025-02-03 18:16:41 +05:30
parent 1f7254ecaa
commit 8fb5ac1f31
21 changed files with 1433 additions and 789 deletions

View File

@@ -2,12 +2,35 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:grocery_app/src/common_widget/name_text_field.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/logic/provider/addTocart_provider.dart';
import 'package:grocery_app/utils/constants/assets_constant.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:provider/provider.dart';
class CardCheckoutScreen extends StatefulWidget {
const CardCheckoutScreen({super.key});
double amount;
String currency;
double originalAmount;
String name;
String phone;
String email;
String userId;
String cartId;
String addressId;
String remarks;
CardCheckoutScreen(
{super.key,
required this.amount,
required this.currency,
required this.originalAmount,
required this.name,
required this.phone,
required this.email,
required this.userId,
required this.cartId,
required this.addressId,
required this.remarks});
@override
State<CardCheckoutScreen> createState() => _CardCheckoutScreenState();
@@ -42,218 +65,300 @@ class _CardCheckoutScreenState extends State<CardCheckoutScreen> {
),
),
),
bottomNavigationBar: Container(
color: Colors.transparent,
height: 60,
child: Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
children: [
const SizedBox(
width: 15,
),
Expanded(
child: InkWell(
onTap: () {},
child: Container(
height: 50,
decoration: BoxDecoration(color: APPCOLOR.lightGreen, borderRadius: BorderRadius.circular(10)),
child: Center(
child: Text(
"Next",
style: context.customRegular(Colors.white, 16),
bottomNavigationBar: Consumer<AddtocartProvider>(
builder: (context, paymentProvider, child) {
return Container(
color: Colors.transparent,
height: 60,
child: Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
children: [
const SizedBox(
width: 15,
),
Expanded(
child: InkWell(
onTap: () {
paymentProvider.orderPaymnet(
context,
widget.amount,
widget.currency,
widget.originalAmount,
widget.name,
widget.phone,
widget.email,
widget.userId,
widget.cartId,
widget.addressId,
widget.remarks);
},
child: Container(
height: 50,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(10)),
child: Center(
child: Text(
"Continue",
style: context.customRegular(Colors.white, 16),
),
),
),
),
),
),
const SizedBox(
width: 15,
),
],
const SizedBox(
width: 15,
),
],
),
),
),
),
);
}),
body: Padding(
padding: context.bodyAllPadding,
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Saved Cards",
style: context.customExtraBold(Colors.black, 16),
),
const SizedBox(
height: 15,
),
Container(
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
const AppNetworkImage(
height: 50,
width: 50,
imageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSeaqcsR_xDLZTOQ7G-NxCe7mLDxFe-xC2JC_DIojrF2CiVJRnviMf9fvGGFZyzyII3jdY&usqp=CAU',
backGroundColor: Colors.transparent),
const SizedBox(
width: 10,
),
Expanded(
child: Text(
"6895 8578 8578 5525",
style: context.customMedium(Colors.black, 16),
)),
const SizedBox(
width: 10,
),
Icon(
Icons.radio_button_off_outlined,
color: Colors.grey.withOpacity(0.3),
)
],
child: SingleChildScrollView(child: Consumer<AddtocartProvider>(
builder: (context, paymentProvider, child) {
return Container(
padding: EdgeInsets.all(16),
height: 250,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Select Payment Method",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
),
const SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
const AppNetworkImage(
height: 50, width: 50, imageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQIXY75wxXccxnFoger82T83BZxDPpMavUI1A&s', backGroundColor: Colors.transparent),
const SizedBox(
width: 10,
),
Expanded(
child: Text(
"6895 8578 8578 5525",
style: context.customMedium(Colors.black, 16),
)),
const SizedBox(
width: 10,
),
Icon(
Icons.radio_button_off_outlined,
color: Colors.grey.withOpacity(0.3),
)
],
SizedBox(height: 20),
// Online Payment Option
ListTile(
leading: Icon(Icons.payment, color: Colors.blue),
title: Text("Online Payment"),
trailing: paymentProvider.selectedPaymentMethod == "Online"
? Icon(Icons.check_circle, color: Colors.green)
: null,
onTap: () {
paymentProvider.selectPaymentMethod("Online");
// Navigator.pop(context);
},
),
),
),
const SizedBox(
height: 10,
),
ClipRRect(
borderRadius: BorderRadius.circular(15),
child: ExpansionTile(
minTileHeight: 0,
backgroundColor: Colors.white,
collapsedBackgroundColor: Colors.white,
//trailing: SizedBox(),
childrenPadding: const EdgeInsets.only(left: 10, right: 10, bottom: 10),
tilePadding: const EdgeInsets.only(right: 10),
title: Container(
width: MediaQuery.sizeOf(context).width,
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Row(
children: [
const AppNetworkImage(
height: 50,
width: 50,
imageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSeaqcsR_xDLZTOQ7G-NxCe7mLDxFe-xC2JC_DIojrF2CiVJRnviMf9fvGGFZyzyII3jdY&usqp=CAU',
backGroundColor: Colors.transparent),
const SizedBox(
width: 10,
),
Expanded(
child: Text(
"6895 8578 8578 5525",
style: context.customMedium(Colors.black, 16),
)),
],
),
),
// Cash on Delivery (COD) Option
ListTile(
leading: Icon(Icons.money, color: Colors.orange),
title: Text("Cash on Delivery (COD)"),
trailing: paymentProvider.selectedPaymentMethod == "COD"
? Icon(Icons.check_circle, color: Colors.green)
: null,
onTap: () {
paymentProvider.selectPaymentMethod("COD");
// Navigator.pop(context);
},
),
children: const [
NameTextField(
name: 'Card Number',
initText: "2352 5285 8545 7528",
),
SizedBox(
height: 10,
),
NameTextField(
name: 'Card Holder Name',
initText: "Smith Watson",
),
SizedBox(
height: 10,
),
Row(
children: [
Expanded(
child: NameTextField(
name: 'Expiry Date',
initText: "09/22",
),
),
SizedBox(
width: 10,
),
Expanded(
child: NameTextField(
name: 'CVV',
initText: "129",
),
)
],
)
],
),
],
),
const SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
const AppNetworkImage(
height: 50, width: 50, imageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTwiraGT0PrLTwZKDg-u25PAlVRgnkdeL96mA&s', backGroundColor: Colors.transparent),
const SizedBox(
width: 10,
),
Expanded(
child: Text(
"Paypal",
style: context.customMedium(Colors.black, 16),
)),
const SizedBox(
width: 10,
),
Icon(
Icons.radio_button_off_outlined,
color: Colors.grey.withOpacity(0.3),
)
],
),
),
),
],
),
),
);
},
)
// Column(
// mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text(
// "Saved Cards",
// style: context.customExtraBold(Colors.black, 16),
// ),
// const SizedBox(
// height: 15,
// ),
// Container(
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15)),
// child: Padding(
// padding: const EdgeInsets.all(10),
// child: Row(
// children: [
// const AppNetworkImage(
// height: 50,
// width: 50,
// imageUrl:
// 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSeaqcsR_xDLZTOQ7G-NxCe7mLDxFe-xC2JC_DIojrF2CiVJRnviMf9fvGGFZyzyII3jdY&usqp=CAU',
// backGroundColor: Colors.transparent),
// const SizedBox(
// width: 10,
// ),
// Expanded(
// child: Text(
// "6895 8578 8578 5525",
// style: context.customMedium(Colors.black, 16),
// )),
// const SizedBox(
// width: 10,
// ),
// Icon(
// Icons.radio_button_off_outlined,
// color: Colors.grey.withOpacity(0.3),
// )
// ],
// ),
// ),
// ),
// const SizedBox(
// height: 10,
// ),
// Container(
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15)),
// child: Padding(
// padding: const EdgeInsets.all(10),
// child: Row(
// children: [
// const AppNetworkImage(
// height: 50,
// width: 50,
// imageUrl:
// 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQIXY75wxXccxnFoger82T83BZxDPpMavUI1A&s',
// backGroundColor: Colors.transparent),
// const SizedBox(
// width: 10,
// ),
// Expanded(
// child: Text(
// "6895 8578 8578 5525",
// style: context.customMedium(Colors.black, 16),
// )),
// const SizedBox(
// width: 10,
// ),
// Icon(
// Icons.radio_button_off_outlined,
// color: Colors.grey.withOpacity(0.3),
// )
// ],
// ),
// ),
// ),
// const SizedBox(
// height: 10,
// ),
// ClipRRect(
// borderRadius: BorderRadius.circular(15),
// child: ExpansionTile(
// minTileHeight: 0,
// backgroundColor: Colors.white,
// collapsedBackgroundColor: Colors.white,
// //trailing: SizedBox(),
// childrenPadding:
// const EdgeInsets.only(left: 10, right: 10, bottom: 10),
// tilePadding: const EdgeInsets.only(right: 10),
// title: Container(
// width: MediaQuery.sizeOf(context).width,
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15)),
// child: Padding(
// padding: const EdgeInsets.only(left: 10, right: 10),
// child: Row(
// children: [
// const AppNetworkImage(
// height: 50,
// width: 50,
// imageUrl:
// 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSeaqcsR_xDLZTOQ7G-NxCe7mLDxFe-xC2JC_DIojrF2CiVJRnviMf9fvGGFZyzyII3jdY&usqp=CAU',
// backGroundColor: Colors.transparent),
// const SizedBox(
// width: 10,
// ),
// Expanded(
// child: Text(
// "6895 8578 8578 5525",
// style: context.customMedium(Colors.black, 16),
// )),
// ],
// ),
// ),
// ),
// children: const [
// NameTextField(
// name: 'Card Number',
// initText: "2352 5285 8545 7528",
// ),
// SizedBox(
// height: 10,
// ),
// NameTextField(
// name: 'Card Holder Name',
// initText: "Smith Watson",
// ),
// SizedBox(
// height: 10,
// ),
// Row(
// children: [
// Expanded(
// child: NameTextField(
// name: 'Expiry Date',
// initText: "09/22",
// ),
// ),
// SizedBox(
// width: 10,
// ),
// Expanded(
// child: NameTextField(
// name: 'CVV',
// initText: "129",
// ),
// )
// ],
// )
// ],
// ),
// ),
// const SizedBox(
// height: 10,
// ),
// Container(
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15)),
// child: Padding(
// padding: const EdgeInsets.all(10),
// child: Row(
// children: [
// const AppNetworkImage(
// height: 50,
// width: 50,
// imageUrl:
// 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTwiraGT0PrLTwZKDg-u25PAlVRgnkdeL96mA&s',
// backGroundColor: Colors.transparent),
// const SizedBox(
// width: 10,
// ),
// Expanded(
// child: Text(
// "Paypal",
// style: context.customMedium(Colors.black, 16),
// )),
// const SizedBox(
// width: 10,
// ),
// Icon(
// Icons.radio_button_off_outlined,
// color: Colors.grey.withOpacity(0.3),
// )
// ],
// ),
// ),
// ),
// ],
// ),
),
),
);
}

View File

@@ -13,6 +13,7 @@ import 'package:grocery_app/src/logic/provider/addTocart_provider.dart';
import 'package:grocery_app/src/logic/provider/bottom_navbar_provider.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/ui/bestdeal/bestdeal_screen.dart';
import 'package:grocery_app/src/ui/card_checkout/card_checkout_screen.dart';
import 'package:grocery_app/src/ui/widgets/custom_icon_button.dart';
import 'package:grocery_app/src/ui/widgets/elevated_button.dart';
@@ -304,7 +305,7 @@ class _MycartState extends State<Mycart> {
});
}
double calculateDiscountPercentage(double basePrice, double discountPrice) {
int calculateDiscountPercentage(double basePrice, double discountPrice) {
print(
"Base Price (Before Discount): $basePrice, Discount Price (After Discount): $discountPrice");
@@ -316,7 +317,8 @@ class _MycartState extends State<Mycart> {
double discountAmount = basePrice - discountPrice;
double discountPercentage = (discountAmount / basePrice) * 100;
return discountPercentage;
print("kjhfjhdsfghjk ${discountPercentage.round()}");
return discountPercentage.round();
}
Widget cartItems() {
@@ -331,7 +333,7 @@ class _MycartState extends State<Mycart> {
padding: EdgeInsets.only(top: 12.h, bottom: 24.h),
child: const Divider(thickness: 1),
),
itemCount: 3, // Display 3 skeleton items
itemCount: 2,
itemBuilder: (context, index) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 10.w),
@@ -1135,8 +1137,6 @@ class AddressBottomSheet extends StatefulWidget {
}
class _AddressBottomSheetState extends State<AddressBottomSheet> {
// String selectedAddress = "Home";
@override
Widget build(BuildContext context) {
return Padding(
@@ -1180,19 +1180,45 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
),
),
SizedBox(height: 16),
ElevatedButton.icon(
onPressed: () {},
label: Text(
"Continue",
style: TextStyle(color: Colors.white, fontSize: 16),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
minimumSize: Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
),
),
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.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);
},
));
// showPaymentMethodBottomSheet(context);
// context.push(MyRoutes.SELECTPAYMENTSCREEN);
//Navigator.pop(context);
},
label: Text(
"Continue",
style: TextStyle(color: Colors.white, fontSize: 16),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green,
minimumSize: Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
),
);
}),
SizedBox(height: 10),
],
),
@@ -1212,6 +1238,13 @@ 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(
@@ -1219,11 +1252,14 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
child: ListTile(
leading: Radio(
value: address.id ?? "",
groupValue: addressProvider
.selectedAddress, // Use provider's value
groupValue: addressProvider.selectedAddress,
activeColor: Colors.green,
onChanged: (value) {
addressProvider.selectAddress(value.toString());
addressProvider.selectAddress(
value.toString(),
address.phoneNumber,
address.name,
address.user!.email);
},
),
title: Text(
@@ -1243,6 +1279,76 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
},
);
}
// void showPaymentMethodBottomSheet(BuildContext context) {
// showModalBottomSheet(
// context: context,
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
// ),
// builder: (context) {
// return Consumer<AddtocartProvider>(
// builder: (context, paymentProvider, child) {
// return Container(
// padding: EdgeInsets.all(16),
// height: 250,
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text(
// "Select Payment Method",
// style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
// ),
// SizedBox(height: 20),
// // Online Payment Option
// ListTile(
// leading: Icon(Icons.payment, color: Colors.blue),
// title: Text("Online Payment"),
// trailing: paymentProvider.selectedPaymentMethod == "Online"
// ? Icon(Icons.check_circle, color: Colors.green)
// : null,
// onTap: () {
// paymentProvider.selectPaymentMethod("Online");
// },
// ),
// // Cash on Delivery (COD) Option
// ListTile(
// leading: Icon(Icons.money, color: Colors.orange),
// title: Text("Cash on Delivery (COD)"),
// trailing: paymentProvider.selectedPaymentMethod == "COD"
// ? Icon(Icons.check_circle, color: Colors.green)
// : null,
// onTap: () {
// paymentProvider.selectPaymentMethod("COD");
// },
// ),
// ElevatedButton.icon(
// onPressed: () {
// //context.push(MyRoutes.SELECTPAYMENTSCREEN);
// //Navigator.pop(context);
// },
// label: Text(
// "Continue",
// style: TextStyle(color: Colors.white, fontSize: 16),
// ),
// style: ElevatedButton.styleFrom(
// backgroundColor: Colors.green,
// minimumSize: Size(double.infinity, 50),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(10)),
// ),
// ),
// ],
// ),
// );
// },
// );
// },
// );
// }
}
class SummaryRow extends StatelessWidget {

View File

@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class PaymentWebView extends StatefulWidget {
final String paymentUrl;
PaymentWebView({required this.paymentUrl});
@override
_PaymentWebViewState createState() => _PaymentWebViewState();
}
class _PaymentWebViewState extends State<PaymentWebView> {
InAppWebViewController? webViewController;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Complete Your Payment")),
body: InAppWebView(
initialUrlRequest: URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
onWebViewCreated: (controller) {
webViewController = controller;
},
onLoadStop: (controller, url) async {
print("Payment page loaded: $url");
},
),
);
}
}

View File

@@ -115,7 +115,7 @@ class _ProductDetailsState extends State<ProductDetails> {
);
}
double calculateDiscountPercentage(double basePrice, double discountPrice) {
int calculateDiscountPercentage(double basePrice, double discountPrice) {
print(
"Base Price (Before Discount): $basePrice, Discount Price (After Discount): $discountPrice");
@@ -127,7 +127,7 @@ class _ProductDetailsState extends State<ProductDetails> {
double discountAmount = basePrice - discountPrice;
double discountPercentage = (discountAmount / basePrice) * 100;
return discountPercentage;
return discountPercentage.round();
}
Widget prodectDtails() {
@@ -231,8 +231,39 @@ class _ProductDetailsState extends State<ProductDetails> {
style:
TextStyle(color: Colors.white, fontSize: 14)),
),
Spacer(),
InkWell(
onTap: () async {
if (await SharedPrefUtils.getToken() != null) {
provider.toggleWishlist(
context, provider.productDetails.data!.id!);
} else {
context.push(MyRoutes.SIGNUP);
}
},
child: Icon(
provider.wishlist
.contains(provider.productDetails.data!.id)
? Icons.favorite
: Icons.favorite_border,
color: provider.wishlist
.contains(provider.productDetails.data!.id)
? Colors.red
: Colors.grey,
),
),
],
),
SizedBox(height: 10),
ReadMoreText(
provider.productDetails.data!.description ?? "",
trimMode: TrimMode.Line,
trimLines: 2,
colorClickableText: APPCOLOR.appGreen,
trimCollapsedText: 'Read More',
trimExpandedText: 'Show less',
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
],
),
),

View File

@@ -171,12 +171,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
trailing: Icon(MdiIcons.chevronRight),
),
ListTile(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return const CardCheckoutScreen();
},
));
onTap: ()
{
// Navigator.of(context).push(MaterialPageRoute(
// builder: (context) {
// return const CardCheckoutScreen();
// },
// ));
},
leading: Icon(MdiIcons.cardOutline),
title: const Text('Payment Method'),