Ali Haider
Ali Haider

Reputation: 384

How can I redirect back to Flutter App from URL?

I am integrating paytabs payment gateway in my flutter application. It opens a payment page in in app browser. When the transaction is completed, it redirects to a return_url. I want to redirect back to my app, so that I can do something after the payment has been processed.

How can this be accomplished?

Upvotes: 6

Views: 13734

Answers (1)

Ali Haider
Ali Haider

Reputation: 384

I found a solution and it worked for me!

InAppWebView

In flutter to open the paytabs transaction page. When the transaction is successful, it redirects me to a return_url. InAppWebView has a method

onLoadStart: (InAppWebViewController controller, String url)

In this method, I checked if the returl_url == url and redirected to my app and closed the InAppWebView accordingly.

onLoadStart: (InAppWebViewController controller, String url) {
          setState(() {
            _con.url = url;
          });
          if (url == "return_url") {
            //close the webview
            _con.webView.goBack();

            //navigate to the desired screen with arguments
            Navigator.of(context).pushReplacementNamed('/OrderSuccess',
                arguments:
                    new RouteArgument(param: 'Credit Card (Paytabs)'));
          }
        },

Upvotes: 6

Related Questions