Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically return back to Flutter app after user completes a web form

I am developing a toll-payment mobile application with Flutter and I need to provide an internet payment (with bank's IPG page) for user to pay her/his toll debt.
What exactly I need is to automatically return back to my Flutter app after user finishes the form and taps on submit button.
How to do that?

like image 834
Mohsen Emami Avatar asked Oct 28 '25 09:10

Mohsen Emami


2 Answers

This may be too late, but you can use Uni Links package to define a URI scheme like: my_great_app://open to be called by your web form to return to the app. That package works for both Android and iOS, and you can define both Deep link or App link, based on your criteria. Most apps use the simpler Deep links for that purpose.

There are also other packages in pub.dev to do that, search "App Link" or "Universal Link" to find more.

like image 181
Sohail Avatar answered Oct 29 '25 23:10

Sohail


This is the code I used in my app for flutterwave payment gateway

Expanded(
          child: Stack(
            children: [
              WebView(
                javascriptMode: JavascriptMode.unrestricted,
                initialUrl: selectedUrl,
                gestureNavigationEnabled: true,
                userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13E233 Safari/601.1',
                onWebViewCreated: (WebViewController webViewController) {
                  _controller.future.then((value) => controllerGlobal = value);
                  _controller.complete(webViewController);
                },
                onPageStarted: (String url) {
                  if(url.contains(AppConstants.BASE_URL)) {
                    bool _isSuccess = url.contains('success');
                    bool _isFailed = url.contains('fail');
                    print('Page started loading: $url');
                    setState(() {
                      _isLoading = true;
                    });
                    if (_isSuccess) {
                      Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (_) => DashBoardScreen()), (route) => false);
                      showAnimatedDialog(context, MyDialog(
                        icon: Icons.done,
                        title: getTranslated('payment_done', context),
                        description: getTranslated('your_payment_successfully_done', context),
                      ), dismissible: false, isFlip: true);
                    } else if (_isFailed) {
                      Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (_) => DashBoardScreen()), (route) => false);
                      showAnimatedDialog(context, MyDialog(
                        icon: Icons.clear,
                        title: getTranslated('payment_failed', context),
                        description: getTranslated('your_payment_failed', context),
                        isFailed: true,
                      ), dismissible: false, isFlip: true);
                    } else if (url == '${AppConstants.BASE_URL}/cancel') {
                      Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (_) => DashBoardScreen()), (route) => false);
                      showAnimatedDialog(context, MyDialog(
                        icon: Icons.clear,
                        title: getTranslated('payment_cancelled', context),
                        description: getTranslated('your_payment_cancelled', context),
                        isFailed: true,
                      ), dismissible: false, isFlip: true);
                    }
                  }
                },
                onPageFinished: (String url) {
                  print('Page finished loading: $url');
                  setState(() {
                    _isLoading = false;
                  });
                },
              ),
like image 24
Saleh Galiwala Avatar answered Oct 29 '25 22:10

Saleh Galiwala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!