payment handler
This commit is contained in:
@@ -992,7 +992,7 @@
|
|||||||
"languageVersion": "3.4"
|
"languageVersion": "3.4"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"generated": "2025-02-03T12:46:17.320058Z",
|
"generated": "2025-02-03T13:28:33.681422Z",
|
||||||
"generator": "pub",
|
"generator": "pub",
|
||||||
"generatorVersion": "3.4.4",
|
"generatorVersion": "3.4.4",
|
||||||
"flutterRoot": "file:///Users/rajeevsingh/Documents/allSoftwares/flutter",
|
"flutterRoot": "file:///Users/rajeevsingh/Documents/allSoftwares/flutter",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -7,7 +7,6 @@ import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
|
|||||||
import 'package:grocery_app/utils/extensions/common_utils.dart';
|
import 'package:grocery_app/utils/extensions/common_utils.dart';
|
||||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||||
|
|
||||||
|
|
||||||
/// Dio class wrapper for sending api request to the network
|
/// Dio class wrapper for sending api request to the network
|
||||||
class DioClient {
|
class DioClient {
|
||||||
final Dio _dio;
|
final Dio _dio;
|
||||||
@@ -178,8 +177,7 @@ class DioClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Response> uploadImage(String url, File imageFile,
|
||||||
Future<Response> uploadImage(String url, File imageFile,
|
|
||||||
{Map<String, dynamic>? additionalFields,
|
{Map<String, dynamic>? additionalFields,
|
||||||
Options? options,
|
Options? options,
|
||||||
CancelToken? cancelToken,
|
CancelToken? cancelToken,
|
||||||
@@ -195,7 +193,8 @@ Future<Response> uploadImage(String url, File imageFile,
|
|||||||
try {
|
try {
|
||||||
String fileName = imageFile.path.split('/').last;
|
String fileName = imageFile.path.split('/').last;
|
||||||
FormData formData = FormData.fromMap({
|
FormData formData = FormData.fromMap({
|
||||||
"image": await MultipartFile.fromFile(imageFile.path, filename: fileName),
|
"image":
|
||||||
|
await MultipartFile.fromFile(imageFile.path, filename: fileName),
|
||||||
...?additionalFields,
|
...?additionalFields,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -215,5 +214,4 @@ Future<Response> uploadImage(String url, File imageFile,
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,8 +153,9 @@ class AddtocartProvider extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
///////////////////////////////////orderPaymnet///////////////////////////
|
|
||||||
|
|
||||||
|
///////////////////////////////////orderPaymnet///////////////////////////
|
||||||
|
bool ispaymentLoader = false;
|
||||||
Future<void> orderPaymnet(
|
Future<void> orderPaymnet(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
double amount,
|
double amount,
|
||||||
@@ -168,41 +169,49 @@ class AddtocartProvider extends ChangeNotifier {
|
|||||||
String addressId,
|
String addressId,
|
||||||
String remarks,
|
String remarks,
|
||||||
) async {
|
) async {
|
||||||
|
ispaymentLoader = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
{
|
"amount": amount,
|
||||||
"amount": amount,
|
"currency": currency,
|
||||||
"currency": currency,
|
"originalAmount": amount,
|
||||||
"originalAmount": amount,
|
"name": name,
|
||||||
"name": name,
|
"phone": phone,
|
||||||
"phone": phone,
|
"email": email,
|
||||||
"email": email,
|
"userId": userI,
|
||||||
"userId": userI,
|
"cartId": cartId,
|
||||||
"cartId": cartId,
|
"addressId": addressId,
|
||||||
"addressId": addressId,
|
"remarks": remarks
|
||||||
"remarks": remarks
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
print("kjdfhgkj ${data}");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var result = await _homeRepo.paymentOrder(data);
|
var result = await _homeRepo.paymentOrder(data);
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(error) {
|
(error) {
|
||||||
|
ispaymentLoader = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
},
|
},
|
||||||
(response) {
|
(response) {
|
||||||
Navigator.push(
|
if (response.data!.instrumentResponse!.redirectInfo != null &&
|
||||||
context,
|
response.data!.instrumentResponse!.redirectInfo != '') {
|
||||||
MaterialPageRoute(
|
Navigator.push(
|
||||||
builder: (context) => PaymentWebView(paymentUrl: ''),
|
context,
|
||||||
),
|
MaterialPageRoute(
|
||||||
);
|
builder: (context) => PaymentWebView(
|
||||||
|
paymentUrl:
|
||||||
|
response.data!.instrumentResponse!.redirectInfo!.url),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
ispaymentLoader = false;
|
||||||
|
notifyListeners();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
ispaymentLoader = false;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import 'package:grocery_app/src/data/banners.dart';
|
|||||||
import 'package:grocery_app/src/data/best_dealProduct.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/check_pin_response.dart';
|
||||||
import 'package:grocery_app/src/data/login_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';
|
import 'package:grocery_app/src/data/product_category.dart';
|
||||||
import 'package:grocery_app/src/data/product_details.dart';
|
import 'package:grocery_app/src/data/product_details.dart';
|
||||||
import 'package:grocery_app/src/data/upload_image.dart';
|
import 'package:grocery_app/src/data/upload_image.dart';
|
||||||
@@ -91,33 +92,28 @@ class ProductRepo {
|
|||||||
|
|
||||||
return right(productCategory);
|
return right(productCategory);
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
|
|
||||||
var error = CustomDioExceptions.handleError(e);
|
var error = CustomDioExceptions.handleError(e);
|
||||||
return left(error);
|
return left(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<ProductCategory> paymentOrder(
|
FutureResult<OrderPaymnet> paymentOrder(data) async {
|
||||||
data) async
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
var response = await _productService.paymentOrder(data);
|
var response = await _productService.paymentOrder(data);
|
||||||
|
print("kjdfglkjfdgjklfgkldj${data} ${response} ");
|
||||||
|
|
||||||
|
OrderPaymnet productCategory = orderPaymnetFromJson(response.toString());
|
||||||
|
|
||||||
ProductCategory productCategory = productCategoryFromJson(response.toString());
|
print("lkjdflkjfhgdkhfgkd ");
|
||||||
|
|
||||||
// final String model = response.toString();
|
// final String model = response.toString();
|
||||||
|
|
||||||
return right(productCategory);
|
return right(productCategory);
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
|
|
||||||
var error = CustomDioExceptions.handleError(e);
|
var error = CustomDioExceptions.handleError(e);
|
||||||
return left(error);
|
return left(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FutureResult<List<Product>> similarProduct(
|
FutureResult<List<Product>> similarProduct(
|
||||||
data, BuildContext context, id) async {
|
data, BuildContext context, id) async {
|
||||||
try {
|
try {
|
||||||
@@ -176,33 +172,30 @@ class ProductRepo {
|
|||||||
return left(error);
|
return left(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FutureResult<String> updateProfile(data) async {
|
|
||||||
|
FutureResult<String> updateProfile(data) async {
|
||||||
try {
|
try {
|
||||||
var response = await _productService.updateProfile(data);
|
var response = await _productService.updateProfile(data);
|
||||||
|
|
||||||
print("kdjfgkljfdkjlghflkgjh ${response}");
|
print("kdjfgkljfdkjlghflkgjh ${response}");
|
||||||
final String model = response.toString();
|
final String model = response.toString();
|
||||||
return right(model);
|
return right(model);
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
var error = CustomDioExceptions.handleError(e);
|
var error = CustomDioExceptions.handleError(e);
|
||||||
return left(error);
|
return left(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureResult<UploadImage> uploadImage(File imageFile) async {
|
||||||
|
|
||||||
FutureResult<UploadImage> uploadImage(File imageFile)
|
|
||||||
async {
|
|
||||||
try {
|
try {
|
||||||
final response = await _productService.uploadImage(imageFile);
|
final response = await _productService.uploadImage(imageFile);
|
||||||
UploadImage upload=uploadImageFromJson(response.toString());
|
UploadImage upload = uploadImageFromJson(response.toString());
|
||||||
return right(upload);
|
return right(upload);
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final error = CustomDioExceptions.handleError(e);
|
final error = CustomDioExceptions.handleError(e);
|
||||||
return left(error);
|
return left(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FutureResult<CheckPinResponse> checkPin(data, pin) async {
|
FutureResult<CheckPinResponse> checkPin(data, pin) async {
|
||||||
try {
|
try {
|
||||||
@@ -270,7 +263,8 @@ FutureResult<String> updateProfile(data) async {
|
|||||||
return left(error);
|
return left(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FutureResult<String> decreaseQuantity(data) async {
|
|
||||||
|
FutureResult<String> decreaseQuantity(data) async {
|
||||||
try {
|
try {
|
||||||
var response = await _productService.decreaseQuantity(data);
|
var response = await _productService.decreaseQuantity(data);
|
||||||
|
|
||||||
@@ -284,9 +278,6 @@ FutureResult<String> decreaseQuantity(data) async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FutureResult<WishListModel> gettAllWishList(data) async {
|
FutureResult<WishListModel> gettAllWishList(data) async {
|
||||||
try {
|
try {
|
||||||
var response = await _productService.gettAllWishList(data);
|
var response = await _productService.gettAllWishList(data);
|
||||||
@@ -337,9 +328,7 @@ FutureResult<String> decreaseQuantity(data) async {
|
|||||||
var response = await _productService.refresh_token(data);
|
var response = await _productService.refresh_token(data);
|
||||||
LoginResponse loginResponse = loginResponseFromJson(response.toString());
|
LoginResponse loginResponse = loginResponseFromJson(response.toString());
|
||||||
|
|
||||||
if (loginResponse.accessToken != null)
|
if (loginResponse.accessToken != null) {
|
||||||
{
|
|
||||||
|
|
||||||
await SharedPrefUtils.setToken(
|
await SharedPrefUtils.setToken(
|
||||||
authToken: loginResponse.accessToken ?? "");
|
authToken: loginResponse.accessToken ?? "");
|
||||||
await SharedPrefUtils.setRefreshToken(
|
await SharedPrefUtils.setRefreshToken(
|
||||||
@@ -349,10 +338,7 @@ FutureResult<String> decreaseQuantity(data) async {
|
|||||||
final String model = response.toString();
|
final String model = response.toString();
|
||||||
|
|
||||||
return right(model);
|
return right(model);
|
||||||
} on DioException catch (e)
|
} on DioException catch (e) {
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
var error = CustomDioExceptions.handleError(e);
|
var error = CustomDioExceptions.handleError(e);
|
||||||
return left(error);
|
return left(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ class ProductService extends ApiService {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
Future paymentOrder(data) async {
|
|
||||||
|
Future paymentOrder(data) async {
|
||||||
|
print("kdjfgkjjkdfgkjdkfgjkdfgj ${data}");
|
||||||
var response = await api.post(APIURL.paymentOrder, data: jsonEncode(data));
|
var response = await api.post(APIURL.paymentOrder, data: jsonEncode(data));
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
@@ -83,23 +85,25 @@ class ProductService extends ApiService {
|
|||||||
await api.delete(APIURL.deleteItem + id, data: jsonEncode(data));
|
await api.delete(APIURL.deleteItem + id, data: jsonEncode(data));
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
Future addAddress(data) async {
|
|
||||||
|
Future addAddress(data) async {
|
||||||
var response = await api.post(APIURL.addAddress, data: jsonEncode(data));
|
var response = await api.post(APIURL.addAddress, data: jsonEncode(data));
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future getProfile(data) async {
|
Future getProfile(data) async {
|
||||||
var response = await api.get(APIURL.getprofile, data: jsonEncode(data));
|
var response = await api.get(APIURL.getprofile, data: jsonEncode(data));
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future updateProfile(data) async {
|
Future updateProfile(data) async {
|
||||||
var response = await api.patch(APIURL.updateProfile, data: jsonEncode(data));
|
var response =
|
||||||
|
await api.patch(APIURL.updateProfile, data: jsonEncode(data));
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<Response> uploadImage(File imageFile,
|
||||||
Future<Response> uploadImage(File imageFile,
|
|
||||||
{Map<String, dynamic>? additionalFields}) async {
|
{Map<String, dynamic>? additionalFields}) async {
|
||||||
const String url = APIURL.uploadImage;
|
const String url = APIURL.uploadImage;
|
||||||
return await api.uploadImage(
|
return await api.uploadImage(
|
||||||
@@ -109,13 +113,11 @@ class ProductService extends ApiService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future getAddress(data) async {
|
||||||
Future getAddress
|
var response = await api.get(APIURL.userAddress, data: jsonEncode(data));
|
||||||
(data) async {
|
|
||||||
var response =
|
|
||||||
await api.get(APIURL.userAddress, data: jsonEncode(data));
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future addToWish(data) async {
|
Future addToWish(data) async {
|
||||||
var response = await api.post(APIURL.addToWish, data: jsonEncode(data));
|
var response = await api.post(APIURL.addToWish, data: jsonEncode(data));
|
||||||
|
|
||||||
@@ -128,7 +130,7 @@ class ProductService extends ApiService {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future decreaseQuantity(data) async {
|
Future decreaseQuantity(data) async {
|
||||||
var response = await api.patch(APIURL.addToCart, data: jsonEncode(data));
|
var response = await api.patch(APIURL.addToCart, data: jsonEncode(data));
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ class _CardCheckoutScreenState extends State<CardCheckoutScreen> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
print("kjdhfkhjghjkdf");
|
||||||
|
|
||||||
paymentProvider.orderPaymnet(
|
paymentProvider.orderPaymnet(
|
||||||
context,
|
context,
|
||||||
widget.amount,
|
widget.amount,
|
||||||
@@ -99,10 +101,12 @@ class _CardCheckoutScreenState extends State<CardCheckoutScreen> {
|
|||||||
color: APPCOLOR.lightGreen,
|
color: APPCOLOR.lightGreen,
|
||||||
borderRadius: BorderRadius.circular(10)),
|
borderRadius: BorderRadius.circular(10)),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: paymentProvider.ispaymentLoader
|
||||||
"Continue",
|
? CircularProgressIndicator()
|
||||||
style: context.customRegular(Colors.white, 16),
|
: Text(
|
||||||
),
|
"Continue",
|
||||||
|
style: context.customRegular(Colors.white, 16),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -908,8 +908,9 @@ class _MycartState extends State<Mycart> {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
Widget cartPlace() {
|
Widget cartPlace() {
|
||||||
return Consumer<AddtocartProvider>(builder: (context, provider, child) {
|
return Consumer<AddtocartProvider>(builder: (context, provider, child)
|
||||||
print("jdhfgkdfkjg ${provider.allitem.createdAt}");
|
{
|
||||||
|
|
||||||
if (provider.isLoaddcartItem) {
|
if (provider.isLoaddcartItem) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(left: 120),
|
padding: const EdgeInsets.only(left: 120),
|
||||||
@@ -1186,10 +1187,12 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
|
|||||||
"prxvsvxvice ${double.parse(paymentProvider.allitem.subtotal.toString())} ${paymentProvider.selecteUserName} ${paymentProvider.selectedAddress} ${paymentProvider.selecteEmail} ${paymentProvider.selecteUserPhone}");
|
"prxvsvxvice ${double.parse(paymentProvider.allitem.subtotal.toString())} ${paymentProvider.selecteUserName} ${paymentProvider.selectedAddress} ${paymentProvider.selecteEmail} ${paymentProvider.selecteUserPhone}");
|
||||||
return ElevatedButton.icon(
|
return ElevatedButton.icon(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
Navigator.of(context).push(MaterialPageRoute(
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return CardCheckoutScreen(
|
return CardCheckoutScreen(
|
||||||
amount: double.parse( paymentProvider.allitem.subtotal.toString()),
|
amount: double.parse(
|
||||||
|
paymentProvider.allitem.subtotal.toString()),
|
||||||
currency: "INR",
|
currency: "INR",
|
||||||
originalAmount: double.parse(
|
originalAmount: double.parse(
|
||||||
paymentProvider.allitem.subtotal.toString()),
|
paymentProvider.allitem.subtotal.toString()),
|
||||||
@@ -1205,7 +1208,6 @@ class _AddressBottomSheetState extends State<AddressBottomSheet> {
|
|||||||
|
|
||||||
// showPaymentMethodBottomSheet(context);
|
// showPaymentMethodBottomSheet(context);
|
||||||
// context.push(MyRoutes.SELECTPAYMENTSCREEN);
|
// context.push(MyRoutes.SELECTPAYMENTSCREEN);
|
||||||
//Navigator.pop(context);
|
|
||||||
},
|
},
|
||||||
label: Text(
|
label: Text(
|
||||||
"Continue",
|
"Continue",
|
||||||
|
|||||||
@@ -1,3 +1,36 @@
|
|||||||
|
// 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");
|
||||||
|
// },
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||||
|
|
||||||
@@ -12,19 +45,62 @@ class PaymentWebView extends StatefulWidget {
|
|||||||
|
|
||||||
class _PaymentWebViewState extends State<PaymentWebView> {
|
class _PaymentWebViewState extends State<PaymentWebView> {
|
||||||
InAppWebViewController? webViewController;
|
InAppWebViewController? webViewController;
|
||||||
|
bool isErrorPage = false; // Track error state
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text("Complete Your Payment")),
|
appBar: AppBar(title: Text("Complete Your Payment")),
|
||||||
body: InAppWebView(
|
body: Stack(
|
||||||
initialUrlRequest: URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
|
children: [
|
||||||
onWebViewCreated: (controller) {
|
Visibility(
|
||||||
webViewController = controller;
|
visible: !isErrorPage, // Show WebView only if there's no error
|
||||||
},
|
child: InAppWebView(
|
||||||
onLoadStop: (controller, url) async {
|
initialUrlRequest:
|
||||||
print("Payment page loaded: $url");
|
URLRequest(url: WebUri.uri(Uri.parse(widget.paymentUrl))),
|
||||||
},
|
onWebViewCreated: (controller) {
|
||||||
|
webViewController = controller;
|
||||||
|
},
|
||||||
|
onLoadStop: (controller, url) async {
|
||||||
|
print("Payment page loaded: $url");
|
||||||
|
},
|
||||||
|
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"),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user