payment handler

This commit is contained in:
2025-02-03 18:58:55 +05:30
parent 8fb5ac1f31
commit 5006eef68d
9 changed files with 162 additions and 85 deletions

View File

@@ -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_inappwebview/flutter_inappwebview.dart';
@@ -12,19 +45,62 @@ class PaymentWebView extends StatefulWidget {
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");
},
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"),
),
],
),
);
}