I am using flutter_inappwebview for my website but whenever i go to payment gateway the netbanking page freeze and shows nothing i tried many things nevertheless i couldnt solve the problem.
here is my code :
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:http/http.dart' as http;
import 'package:razorpay_flutter/razorpay_flutter.dart';
import 'package:url_launcher/url_launcher.dart';
class WebViewPage extends StatefulWidget {
const WebViewPage({super.key});
@override
State<WebViewPage> createState() => _WebViewPageState();
}
class _WebViewPageState extends State<WebViewPage> {
late InAppWebViewController webViewController;
final _razorpay = Razorpay();
List<dynamic> paymentData = [];
fetchData() async {
const url = "https://api.redesyn.com/orders/place?payment_mode=prepaid";
final uri = Uri.parse(url);
final response = await http.get(uri);
final body = response.body;
final json = jsonDecode(body);
setState(() {
paymentData = json['data'];
});
print("11111111111*****************************@@@@@@@@@@@@@@#####%&&&& ");
}
InAppWebViewGroupOptions initialOptions = InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
useShouldOverrideUrlLoading: true,
mediaPlaybackRequiresUserGesture: false,
javaScriptEnabled: true,
verticalScrollBarEnabled: false,
horizontalScrollBarEnabled: false),
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
),
ios: IOSInAppWebViewOptions(
allowsInlineMediaPlayback: true,
),
);
void _handlePaymentSuccess(PaymentSuccessResponse response) {
}
void _handlePaymentError(PaymentFailureResponse response) {
}
void _handleExternalWallet(ExternalWalletResponse response) {
}
@override
void initState() {
super.initState();
// fetchData();
_razorpay.on(Razorpay.EVENT_PAYMENT_SUCCESS, _handlePaymentSuccess);
_razorpay.on(Razorpay.EVENT_PAYMENT_ERROR, _handlePaymentError);
_razorpay.on(Razorpay.EVENT_EXTERNAL_WALLET, _handleExternalWallet);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: WillPopScope(
onWillPop: () async {
var isLastPage = await webViewController.canGoBack();
if (isLastPage) {
webViewController.goBack();
return false;
}
return true;
},
child: Stack(
children: [
InAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse("https://demo.redesyn.com/"),
headers: {
'X-Client-Type': 'app',
},
),
onWebViewCreated: (InAppWebViewController controller) {
webViewController = controller;
},
androidOnPermissionRequest:
(controller, origin, resources) async {
return PermissionRequestResponse(
resources: resources,
action: PermissionRequestResponseAction.GRANT);
},
shouldOverrideUrlLoading: (controller, navigationAction) async {
var url = navigationAction.request.url!;
print("22222222222@@@@@@@@@@@@@@@@@@@@************ $url");
if (url.toString().contains(
"https://checkout.razorpay.com/v1/checkout.js")) {
print(
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&********************************");
}
if (![
"http",
"https",
"file",
"chrome",
"data",
"javascript",
"about"
].contains(url.scheme)) {
if (await canLaunchUrl(url)) {
await launchUrl(url,
mode: LaunchMode.externalApplication);
return NavigationActionPolicy.CANCEL;
}
}
// https://checkout.razorpay.com/v1/checkout.js
// if (url ==
// "https://dev.redesyn.com/orders/place?payment_mode=prepaid") {
// if (await canLaunchUrl(url)) {
// fetchData();
// return NavigationActionPolicy.CANCEL;
// }
// }
return NavigationActionPolicy.ALLOW;
},
initialOptions: initialOptions,
),
],
),
),
),
);
}
}
I am trying to intercept the the razorpay url and use the native, but it is doing nothing, i have tried many things provided by internet but nothing works.