I'm working on the Flutter app, and need to create a callback url after a customer success/fails payment. Which event/function can be used with webview_flutter?
I was check the same questions here but didn't find solutions
CodePudding user response:
You can create webview client and use shouldOverrideUrlLoading
or onLoadResource
to create a callback url in webview_flutter
CodePudding user response:
You can use webview_flutter and do what you want in navigationDelegate callback
WebView(
initialUrl: yourPaymenntUrl,
javascriptMode: JavascriptMode.unrestricted,
navigationDelegate: (navigationDelegate) async {
if (navigationDelegate.url
.contains(yourReturnUrl)) {
// payment completed
// do what ever you want
String? merchantId = Uri.parse(navigationDelegate.url)
.queryParameters['merchantId'];
Navigator.pop(context, merchantId);
} else if (navigationDelegate.url
.contains(cancelUrl)) {
// TODO implementation
Navigator.pop(context);
}
return NavigationDecision.navigate;
},
)