Skip to content

Instantly share code, notes, and snippets.

@unijad
Last active April 11, 2023 15:30
Show Gist options
  • Save unijad/71f6e85d65c23023b0e031f6f1c76d6b to your computer and use it in GitHub Desktop.
Save unijad/71f6e85d65c23023b0e031f6f1c76d6b to your computer and use it in GitHub Desktop.
Flutter: Stably Ramp Websdk inside WebViewWidget example
import 'package:flutter/material.dart';
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';
import 'package:webview_flutter/webview_flutter.dart';
class RampWidget extends StatefulWidget {
const RampWidget({super.key});
@override
State<RampWidget> createState() => _RampWidgetState();
}
class _RampWidgetState extends State<RampWidget> {
late final WebViewController _controller;
@override
void initState() {
super.initState();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setBackgroundColor(const Color(0x00000000))
..setNavigationDelegate(
NavigationDelegate(
onProgress: (int progress) {},
onPageStarted: (String url) {},
onPageFinished: (String url) {},
onWebResourceError: (WebResourceError error) {},
onNavigationRequest: (NavigationRequest request) {
if (request.url !== 'about:blank' && !request.url.contains('stably.io') &&
(request.url.contains('socure.com') ||
request.url.contains('plaid.com'))) {
launch(request.url);
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(
Uri.parse(
'https://ramp-beta.stably.io/?integrationId=test_younis_flutter',
),
);
}
@override
Widget build(BuildContext context) {
// _launchRamp(context);
return Container(
alignment: Alignment.center,
child: WebViewWidget(controller: _controller),
);
}
void _launchUrl(BuildContext context, String url) async {
try {
await launch(
url,
customTabsOption: CustomTabsOption(
toolbarColor: Theme.of(context).primaryColor,
enableDefaultShare: false,
enableUrlBarHiding: true,
showPageTitle: true,
animation: CustomTabsSystemAnimation.fade(),
extraCustomTabs: const <String>[
// ref. https://play.google.com/store/apps/details?id=org.mozilla.firefox
'org.mozilla.firefox',
// ref. https://play.google.com/store/apps/details?id=com.microsoft.emmx
'com.microsoft.emmx',
],
),
safariVCOption: SafariViewControllerOption(
preferredBarTintColor: Theme.of(context).primaryColor,
preferredControlTintColor: Colors.white,
barCollapsingEnabled: true,
entersReaderIfAvailable: false,
dismissButtonStyle: SafariViewControllerDismissButtonStyle.close,
),
);
} catch (e) {
// An exception is thrown if browser app is not installed on Android device.
debugPrint(e.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment