116 lines
3.9 KiB
Dart
116 lines
3.9 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:traderscircuit/Utils/api_urls.dart';
|
|
|
|
class WebViewSubscription extends StatefulWidget {
|
|
WebViewSubscription({
|
|
super.key,
|
|
required this.token,
|
|
});
|
|
String token;
|
|
|
|
@override
|
|
State<WebViewSubscription> createState() => _WebViewSubscriptionState();
|
|
}
|
|
|
|
class _WebViewSubscriptionState extends State<WebViewSubscription> {
|
|
final GlobalKey webViewKey = GlobalKey();
|
|
|
|
@override
|
|
void initState() {
|
|
//getData();
|
|
super.initState();
|
|
}
|
|
|
|
InAppWebViewController? webViewController;
|
|
InAppWebViewController? webViewPopupController;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return WillPopScope(
|
|
onWillPop: () async {
|
|
final controller = webViewController;
|
|
if (controller != null) {
|
|
if (await controller.canGoBack()) {
|
|
Get.back(result: true);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
Get.back(result: true);
|
|
return false;
|
|
},
|
|
child: Scaffold(
|
|
body: InAppWebView(
|
|
key: webViewKey,
|
|
initialSettings: InAppWebViewSettings(
|
|
allowsBackForwardNavigationGestures: true,
|
|
supportMultipleWindows: true,
|
|
javaScriptCanOpenWindowsAutomatically: true,
|
|
javaScriptEnabled: true,
|
|
// useOnDownloadStart: true,
|
|
// useOnLoadResource: true,
|
|
// preferredContentMode: UserPreferredContentMode.MOBILE,
|
|
// useShouldOverrideUrlLoading: true,
|
|
// mediaPlaybackRequiresUserGesture: true,
|
|
// allowFileAccessFromFileURLs: true,
|
|
// allowUniversalAccessFromFileURLs: true
|
|
),
|
|
onLoadStart: (controller, Uri? uri) {
|
|
print("Load Started: $uri");
|
|
},
|
|
onCreateWindow: (controller, createWindowRequest) async {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
content: SizedBox(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: 400,
|
|
child: InAppWebView(
|
|
windowId: createWindowRequest.windowId,
|
|
initialSettings: InAppWebViewSettings(
|
|
allowsBackForwardNavigationGestures: true,
|
|
supportMultipleWindows: true,
|
|
javaScriptCanOpenWindowsAutomatically: true,
|
|
javaScriptEnabled: true,
|
|
useOnDownloadStart: true,
|
|
useOnLoadResource: true,
|
|
preferredContentMode: UserPreferredContentMode.MOBILE,
|
|
// useShouldOverrideUrlLoading: true,
|
|
mediaPlaybackRequiresUserGesture: true,
|
|
allowFileAccessFromFileURLs: true,
|
|
allowUniversalAccessFromFileURLs: true),
|
|
onWebViewCreated: (InAppWebViewController controller) {
|
|
webViewPopupController = controller;
|
|
},
|
|
onLoadStart:
|
|
(InAppWebViewController controller, Uri? url) {
|
|
print("onLoadStart popup $url");
|
|
},
|
|
onLoadStop:
|
|
(InAppWebViewController controller, Uri? url) {
|
|
print("onLoadStop popup $url");
|
|
},
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
|
|
return true;
|
|
},
|
|
initialUrlRequest: URLRequest(
|
|
url: WebUri(
|
|
"https://tradercircuit.betadelivery.com/my-subscription-page"),
|
|
headers: {
|
|
"access-token": widget.token,
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|