2021-03-17 10:32:22 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
class WebViewPage extends BasePage {
|
|
|
|
WebViewPage({@required this.url});
|
|
|
|
|
|
|
|
final String url;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get title => S.current.buy;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget body(BuildContext context) => WebViewPageBody(url: url);
|
|
|
|
}
|
|
|
|
|
|
|
|
class WebViewPageBody extends StatefulWidget {
|
|
|
|
WebViewPageBody({this.url});
|
|
|
|
|
|
|
|
final String url;
|
|
|
|
|
|
|
|
@override
|
|
|
|
WebViewPageBodyState createState() => WebViewPageBodyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class WebViewPageBodyState extends State<WebViewPageBody> {
|
2021-03-17 14:14:48 +00:00
|
|
|
String orderId;
|
|
|
|
WebViewController _webViewController;
|
|
|
|
GlobalKey _webViewkey;
|
2021-03-17 10:32:22 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2021-03-17 14:14:48 +00:00
|
|
|
_webViewkey = GlobalKey();
|
|
|
|
|
2021-03-17 10:32:22 +00:00
|
|
|
if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return WebView(
|
2021-03-17 14:14:48 +00:00
|
|
|
key: _webViewkey,
|
|
|
|
initialUrl: widget.url,
|
|
|
|
javascriptMode: JavascriptMode.unrestricted,
|
|
|
|
onWebViewCreated: (WebViewController controller) =>
|
|
|
|
setState(() => _webViewController = controller),
|
|
|
|
navigationDelegate: (req) async {
|
|
|
|
final currentUrl = await _webViewController?.currentUrl() ?? '';
|
|
|
|
|
|
|
|
if (currentUrl.contains('processing') ||
|
|
|
|
currentUrl.contains('completed')) {
|
|
|
|
final urlParts = currentUrl.split('/');
|
|
|
|
orderId = urlParts.last;
|
|
|
|
print(orderId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NavigationDecision.navigate;
|
|
|
|
});
|
2021-03-17 10:32:22 +00:00
|
|
|
}
|
2021-03-17 14:14:48 +00:00
|
|
|
}
|