Last active
April 13, 2023 19:56
-
-
Save markusait/071e302052ac4e06144f1863578bf280 to your computer and use it in GitHub Desktop.
Open up Stably Ramp Trade page in a WebView and continue checkout in user's mobile browser when proceed is clicked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:url_launcher/url_launcher.dart'; | |
class _WebViewExampleState extends State<WebViewExample> { | |
final String url = 'https://ramp.stably.io/?address=GDXLL7ERK46AL2ISBAA2N3YZOF4RNA3L75MYRYHRJL62BFOXN3Z53RDG&network=stellar&asset=USDC&lock=true&_blank=1'; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Webview Example'), | |
), | |
body: WebView( | |
initialUrl: url, | |
javascriptMode: JavascriptMode.unrestricted, | |
navigationDelegate: (NavigationRequest request) { | |
if (request.url.startsWith('browser://')) { | |
_launchURL(request.url.replaceFirst('browser://', 'https://')); | |
return NavigationDecision.prevent; | |
} | |
return NavigationDecision.navigate; | |
}, | |
), | |
); | |
} | |
void _launchURL(String url) async { | |
if (await canLaunch(url)) { | |
await launch(url); | |
} else { | |
throw 'Could not launch $url'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment