payment success
This commit is contained in:
@@ -908,9 +908,7 @@ class _MycartState extends State<Mycart> {
|
||||
// }
|
||||
|
||||
Widget cartPlace() {
|
||||
return Consumer<AddtocartProvider>(builder: (context, provider, child)
|
||||
{
|
||||
|
||||
return Consumer<AddtocartProvider>(builder: (context, provider, child) {
|
||||
if (provider.isLoaddcartItem) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 120),
|
||||
@@ -992,9 +990,7 @@ class _MycartState extends State<Mycart> {
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('\$22 Place Order', style: TextStyle(fontSize: 16))
|
||||
],
|
||||
children: [Text('Place Order', style: TextStyle(fontSize: 16))],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,319 +1,3 @@
|
||||
// import 'package:flutter/material.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/best_dealProduct.dart';
|
||||
// import 'package:grocery_app/src/data/product_model.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/header.dart';
|
||||
// import 'package:grocery_app/src/ui/widgets/custom_title.dart';
|
||||
// import 'package:grocery_app/utils/constants/color_constant.dart';
|
||||
// import 'package:grocery_app/utils/extensions/uicontext.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
|
||||
// class FavouriteScreen extends StatefulWidget {
|
||||
// @override
|
||||
// _FavouriteScreenState createState() => _FavouriteScreenState();
|
||||
// }
|
||||
|
||||
// class _FavouriteScreenState extends State<FavouriteScreen>
|
||||
// with SingleTickerProviderStateMixin {
|
||||
// late AnimationController _animationController;
|
||||
// late Animation<double> _animation;
|
||||
|
||||
// @override
|
||||
// void initState() {
|
||||
// Provider.of<ProductProvider>(context, listen: false)
|
||||
// .gettAllWishList(context);
|
||||
// _animationController = AnimationController(
|
||||
// duration: const Duration(milliseconds: 1000),
|
||||
// vsync: this,
|
||||
// );
|
||||
|
||||
// super.initState();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// void dispose() {
|
||||
// _animationController.dispose();
|
||||
// super.dispose();
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return SafeArea(
|
||||
// child: Scaffold(
|
||||
// body: Padding(
|
||||
// padding: context.bodyAllPadding.copyWith(
|
||||
// top: 0,
|
||||
// ),
|
||||
// child: Column(
|
||||
// children: [
|
||||
// Header(),
|
||||
// itemList(),
|
||||
// Consumer<ProductProvider>(
|
||||
// builder: (context, wishListProvider, _) {
|
||||
// if (wishListProvider.productDatum.isEmpty) {
|
||||
// return SizedBox.shrink();
|
||||
// } else {
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.only(),
|
||||
// child: Container(
|
||||
// height: 80,
|
||||
// width: MediaQuery.sizeOf(context).width,
|
||||
// decoration: BoxDecoration(
|
||||
// color: APPCOLOR.lightGreen,
|
||||
// borderRadius: BorderRadius.circular(15)),
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.all(10),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// SizedBox(
|
||||
// width: 80,
|
||||
// child: Stack(
|
||||
// children: [
|
||||
// Container(
|
||||
// height: 70,
|
||||
// width: 70,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.white.withOpacity(0.5),
|
||||
// borderRadius:
|
||||
// BorderRadius.circular(10)),
|
||||
// ),
|
||||
// Positioned(
|
||||
// left: 20,
|
||||
// bottom: 0,
|
||||
// top: 0,
|
||||
// right: 0,
|
||||
// child: AppNetworkImage(
|
||||
// height: 70,
|
||||
// width: 70,
|
||||
// radius: 10,
|
||||
// imageUrl: wishListProvider
|
||||
// .productDatumlastImageurl ??
|
||||
// "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
|
||||
// backGroundColor: Colors.white,
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// width: 10,
|
||||
// ),
|
||||
// Text(
|
||||
// wishListProvider.productDatum.length.toString() ??
|
||||
// "",
|
||||
// style: context.customRegular(Colors.white, 18),
|
||||
// ),
|
||||
// const Spacer(),
|
||||
// InkWell(
|
||||
// onTap: () {
|
||||
// context.read<BottomNavProvider>().setIndex(2);
|
||||
// },
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Text(
|
||||
// 'View Cart',
|
||||
// style:
|
||||
// context.customMedium(Colors.white, 24),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// width: 10,
|
||||
// ),
|
||||
// const Icon(
|
||||
// Icons.arrow_forward,
|
||||
// color: Colors.white,
|
||||
// size: 35,
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// )
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
// Widget itemList() {
|
||||
// return Consumer<ProductProvider>(builder: (context, provider, child) {
|
||||
// if (provider.isWishListItemLoadingg) {
|
||||
// return Expanded(child: Center(child: CircularProgressIndicator()));
|
||||
// } else if (provider.wishListItem.isEmpty) {
|
||||
// return Expanded(child: Center(child: Text('No products available')));
|
||||
// } else {
|
||||
// return Expanded(
|
||||
// child: ListView.separated(
|
||||
// itemCount: provider.wishListItem.length,
|
||||
// shrinkWrap: true,
|
||||
// padding: const EdgeInsets.all(16),
|
||||
// itemBuilder: (_, index) {
|
||||
// final item = provider.wishListItem[index];
|
||||
// final product = item.product!;
|
||||
// final productId = product.id!;
|
||||
|
||||
// final animation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
// CurvedAnimation(
|
||||
// parent: _animationController,
|
||||
// curve: Interval(
|
||||
// (0.5 / provider.wishListItem.length) * index,
|
||||
// 1,
|
||||
// curve: Curves.easeOut,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
|
||||
// _animationController.forward(from: 0);
|
||||
|
||||
// return GestureDetector(
|
||||
// onTap: () {
|
||||
// context.push(MyRoutes.PRODUCTDETAILS, extra: productId);
|
||||
// },
|
||||
// child: Container(
|
||||
// padding: EdgeInsets.all(8),
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.white,
|
||||
// borderRadius: BorderRadius.circular(10),
|
||||
// boxShadow: [
|
||||
// BoxShadow(
|
||||
// color: Colors.grey.withOpacity(0.1),
|
||||
// blurRadius: 5,
|
||||
// offset: Offset(2, 2),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// child: Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// Flexible(
|
||||
// flex: 3,
|
||||
// child: Container(
|
||||
// height: 100,
|
||||
// width: 100,
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(10),
|
||||
// color: APPCOLOR.bgGrey,
|
||||
// ),
|
||||
// child: ClipRRect(
|
||||
// borderRadius: BorderRadius.circular(10),
|
||||
// child: AppNetworkImage(
|
||||
// imageUrl: item
|
||||
// .product!.productImages!.first.url ??
|
||||
// "https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png",
|
||||
// backGroundColor: APPCOLOR.bgGrey,
|
||||
// height: 20,
|
||||
// width: 20,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Flexible(
|
||||
// flex: 4,
|
||||
// child: Padding(
|
||||
// padding: const EdgeInsets.only(left: 10),
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
// children: [
|
||||
// Text(
|
||||
// product.name ?? "",
|
||||
|
||||
// style: context.customMedium(
|
||||
// APPCOLOR.balck1A1A1A, 14),
|
||||
// //textAlign: TextAlign.center,
|
||||
// maxLines: 2,
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// ),
|
||||
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
// children: [
|
||||
// Text(
|
||||
// "\$${product.discountPrice}",
|
||||
// style: context.customSemiBold(
|
||||
// Colors.black, 14),
|
||||
// ),
|
||||
// SizedBox(width: 5),
|
||||
// Text(
|
||||
// "\$${product.basePrice ?? ""}",
|
||||
// style: context
|
||||
// .customMedium(
|
||||
// Colors.grey.withOpacity(0.8), 12)
|
||||
// .copyWith(
|
||||
// decoration:
|
||||
// TextDecoration.lineThrough,
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// SizedBox(height: 10),
|
||||
// // Add to Cart Button
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Spacer(),
|
||||
// Align(
|
||||
// alignment: Alignment.centerRight,
|
||||
// child: GestureDetector(
|
||||
// onTap: () async {
|
||||
// print("Add to Cart Pressed for ${product.id}");
|
||||
|
||||
// await provider.addToCartWithWishlist(
|
||||
// context,
|
||||
// product.id!,
|
||||
// product,
|
||||
// product.productImages![index].url);
|
||||
// },
|
||||
// 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: provider.isLoading[product.id] ?? false
|
||||
// ? Padding(
|
||||
// padding: const EdgeInsets.all(8.0),
|
||||
// child: Container(
|
||||
// height: 10,
|
||||
// width: 10,
|
||||
// child: CircularProgressIndicator(
|
||||
// color: Colors.white,
|
||||
// strokeWidth: 2),
|
||||
// ),
|
||||
// )
|
||||
// : Text(
|
||||
// 'Add',
|
||||
// style: context.customRegular(
|
||||
// Colors.white, 12),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// separatorBuilder: (_, __) => Divider(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:grocery_app/src/common_widget/network_image.dart';
|
||||
@@ -364,6 +48,91 @@ class _FavouriteScreenState extends State<FavouriteScreen>
|
||||
children: [
|
||||
Header(),
|
||||
itemList(),
|
||||
Consumer<ProductProvider>(
|
||||
builder: (context, wishListProvider, _) {
|
||||
if (wishListProvider.productDatum.isEmpty) {
|
||||
return SizedBox.shrink();
|
||||
} else {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(),
|
||||
child: Container(
|
||||
height: 80,
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
decoration: BoxDecoration(
|
||||
color: APPCOLOR.lightGreen,
|
||||
borderRadius: BorderRadius.circular(15)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 80,
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: 70,
|
||||
width: 70,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.5),
|
||||
borderRadius:
|
||||
BorderRadius.circular(10)),
|
||||
),
|
||||
Positioned(
|
||||
left: 20,
|
||||
bottom: 0,
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: AppNetworkImage(
|
||||
height: 70,
|
||||
width: 70,
|
||||
radius: 10,
|
||||
imageUrl: wishListProvider
|
||||
.productDatumlastImageurl ??
|
||||
"https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
|
||||
backGroundColor: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(
|
||||
wishListProvider.productDatum.length.toString() ??
|
||||
"",
|
||||
style: context.customRegular(Colors.white, 18),
|
||||
),
|
||||
const Spacer(),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
context.read<BottomNavProvider>().setIndex(2);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'View Cart',
|
||||
style:
|
||||
context.customMedium(Colors.white, 24),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const Icon(
|
||||
Icons.arrow_forward,
|
||||
color: Colors.white,
|
||||
size: 35,
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
71
lib/src/ui/payment/payment_failure_screen.dart
Normal file
71
lib/src/ui/payment/payment_failure_screen.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:grocery_app/utils/constants/assets_constant.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
|
||||
class PaymentFailureScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
centerTitle: true,
|
||||
leading: Center(
|
||||
child: SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
APPASSETS.back,
|
||||
height: 20,
|
||||
width: 20,
|
||||
)),
|
||||
),
|
||||
),
|
||||
title: const Text(
|
||||
"Payment Failed",
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
InkWell(
|
||||
onTap: () {},
|
||||
child: Icon(
|
||||
MdiIcons.magnify,
|
||||
size: 35,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, color: Colors.red, size: 80),
|
||||
SizedBox(height: 10),
|
||||
Text("Payment Failed",
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 10),
|
||||
Text("Something went wrong. Please try again.",
|
||||
textAlign: TextAlign.center),
|
||||
SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Navigate back
|
||||
},
|
||||
child: Text("Try Again"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
72
lib/src/ui/payment/payment_success_screen.dart
Normal file
72
lib/src/ui/payment/payment_success_screen.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:grocery_app/src/core/routes/routes.dart';
|
||||
import 'package:grocery_app/utils/constants/assets_constant.dart';
|
||||
import 'package:grocery_app/utils/extensions/extensions.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
|
||||
class PaymentSuccessScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
centerTitle: true,
|
||||
leading: Center(
|
||||
child: SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: InkWell(
|
||||
onTap: ()
|
||||
{
|
||||
context.clearAndPush(routePath: MyRoutes.BOTTOMNAV);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
APPASSETS.back,
|
||||
height: 20,
|
||||
width: 20,
|
||||
)),
|
||||
),
|
||||
),
|
||||
title: const Text(
|
||||
"Payment Successful",
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
InkWell(
|
||||
onTap: () {},
|
||||
child: Icon(
|
||||
MdiIcons.magnify,
|
||||
size: 35,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.check_circle, color: Colors.green, size: 80),
|
||||
SizedBox(height: 10),
|
||||
Text("Payment Successful!",
|
||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 10),
|
||||
Text("Thank you for your purchase.", textAlign: TextAlign.center),
|
||||
SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Navigate back
|
||||
},
|
||||
child: Text("Go to Home"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:grocery_app/src/core/routes/routes.dart';
|
||||
import 'package:grocery_app/utils/extensions/extensions.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");
|
||||
|
||||
// ✅ Check if payment is successful
|
||||
if (url.toString().contains("success")) {
|
||||
context.push(MyRoutes.SUCCESSPAYMENT);
|
||||
|
||||
print("kjdsfkjghdfhgkjdfhgkjdf");
|
||||
// Navigator.pop(context, true);
|
||||
} else if (url.toString().contains("failure")) {
|
||||
context.push(MyRoutes.PAYMENTFAILD);
|
||||
|
||||
print("faild");
|
||||
// Navigator.pop(context, false);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
|
||||
@@ -12,101 +62,68 @@
|
||||
|
||||
// class _PaymentWebViewState extends State<PaymentWebView> {
|
||||
// InAppWebViewController? webViewController;
|
||||
// bool isErrorPage = false; // Track error state
|
||||
|
||||
// @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");
|
||||
// },
|
||||
// body: Stack(
|
||||
// children: [
|
||||
// Visibility(
|
||||
// visible: !isErrorPage, // Show WebView only if there's no error
|
||||
// child: InAppWebView(
|
||||
// initialUrlRequest:
|
||||
// URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
|
||||
// onWebViewCreated: (controller) {
|
||||
// webViewController = controller;
|
||||
// },
|
||||
// onLoadStop: (controller, url) async {
|
||||
// print("Payment page loaded: $url");
|
||||
|
||||
// // ✅ Check if payment is successful
|
||||
// if (url.toString().contains("success")) {
|
||||
// Navigator.pop(context, true); // Send success result
|
||||
// } else if (url.toString().contains("failure")) {
|
||||
// Navigator.pop(context, false); // Send failure result
|
||||
// }
|
||||
// },
|
||||
// onReceivedHttpError: (controller, request, response) {
|
||||
// if (response.statusCode == 404) {
|
||||
// setState(() {
|
||||
// isErrorPage = true;
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// if (isErrorPage) _buildErrorPage(context), // Show custom error page
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
// Widget _buildErrorPage(BuildContext context) {
|
||||
// return Center(
|
||||
// child: Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// Icon(Icons.error_outline, color: Colors.red, size: 80),
|
||||
// SizedBox(height: 10),
|
||||
// Text("Payment Failed",
|
||||
// style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
// SizedBox(height: 10),
|
||||
// Text("Something went wrong. Please try again.",
|
||||
// textAlign: TextAlign.center),
|
||||
// SizedBox(height: 20),
|
||||
// ElevatedButton(
|
||||
// onPressed: () {
|
||||
// Navigator.pop(context); // Navigate back to previous screen
|
||||
// },
|
||||
// child: Text("Go Back"),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
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;
|
||||
bool isErrorPage = false; // Track error state
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text("Complete Your Payment")),
|
||||
body: Stack(
|
||||
children: [
|
||||
Visibility(
|
||||
visible: !isErrorPage, // Show WebView only if there's no error
|
||||
child: InAppWebView(
|
||||
initialUrlRequest:
|
||||
URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
|
||||
onWebViewCreated: (controller) {
|
||||
webViewController = controller;
|
||||
},
|
||||
onLoadStop: (controller, url) async {
|
||||
print("Payment page loaded: $url");
|
||||
|
||||
// ✅ Check if payment is successful
|
||||
if (url.toString().contains("success")) {
|
||||
Navigator.pop(context, true); // Send success result
|
||||
} else if (url.toString().contains("failure")) {
|
||||
Navigator.pop(context, false); // Send failure result
|
||||
}
|
||||
},
|
||||
onReceivedHttpError: (controller, request, response) {
|
||||
if (response.statusCode == 404) {
|
||||
setState(() {
|
||||
isErrorPage = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
if (isErrorPage) _buildErrorPage(context), // Show custom error page
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorPage(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.error_outline, color: Colors.red, size: 80),
|
||||
SizedBox(height: 10),
|
||||
Text("Payment Failed",
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 10),
|
||||
Text("Something went wrong. Please try again.",
|
||||
textAlign: TextAlign.center),
|
||||
SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context); // Navigate back to previous screen
|
||||
},
|
||||
child: Text("Go Back"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,21 +40,7 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
Provider.of<ProductProvider>(context, listen: false)
|
||||
.getProduuctDetails(context, widget.id);
|
||||
|
||||
// productId = widget.product.id;
|
||||
// Future.delayed(Duration.zero, () {
|
||||
// Provider.of<ProductProvider>(context, listen: false)
|
||||
// .setProductPrice(double.parse(widget.product.discountPrice));
|
||||
|
||||
// Provider.of<ProductProvider>(context, listen: false)
|
||||
// .similarProductprovider(context, widget.product.id);
|
||||
// });
|
||||
|
||||
// Timer.periodic(Duration(seconds: 3), (timer) {
|
||||
// setState(() {
|
||||
// selectedImage =
|
||||
// (selectedImage + 1) % widget.product.productImages!.length;
|
||||
// });
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
double value = 3.5;
|
||||
@@ -232,6 +218,7 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
TextStyle(color: Colors.white, fontSize: 14)),
|
||||
),
|
||||
Spacer(),
|
||||
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
if (await SharedPrefUtils.getToken() != null) {
|
||||
@@ -241,17 +228,27 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
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,
|
||||
),
|
||||
child: provider.iswishloading
|
||||
? Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.green,
|
||||
strokeWidth: 1,
|
||||
),
|
||||
)
|
||||
: 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),
|
||||
@@ -808,7 +805,8 @@ class _ProductDetailsState extends State<ProductDetails> {
|
||||
});
|
||||
}
|
||||
|
||||
Widget bottomBar() {
|
||||
Widget bottomBar()
|
||||
{
|
||||
return Consumer<ProductProvider>(builder: (context, cartProvider, child) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
|
||||
Reference in New Issue
Block a user