HighchartsView constructor
HighchartsView({})
Implementation
HighchartsView({
super.key,
this.body,
this.debug = false,
this.foot,
this.head,
this.keepAlive = true,
this.onError,
this.onLoaded,
this.onLoading,
this.onMounted,
}) {
PlatformWebViewControllerCreationParams params;
if (WebViewPlatform.instance is AndroidWebViewPlatform) {
params = AndroidWebViewControllerCreationParams();
} else if (WebViewPlatform.instance is WebKitWebViewPlatform) {
params = WebKitWebViewControllerCreationParams();
} else {
params = const PlatformWebViewControllerCreationParams();
}
webViewController = WebViewController.fromPlatformCreationParams(params);
if (webViewController.platform is WebKitWebViewController) {
(webViewController.platform as WebKitWebViewController)
.setInspectable(true);
}
if (webViewController.platform is AndroidWebViewController ||
webViewController.platform is WebKitWebViewController) {
webViewController
..setBackgroundColor(const Color(0x00000000))
..setJavaScriptMode(JavaScriptMode.unrestricted);
}
webViewController
..setNavigationDelegate(NavigationDelegate(onPageFinished: (_) {
if (onMounted != null) {
onMounted!(this);
}
}))
..addJavaScriptChannel(
'highcharts_flutter_channel',
onMessageReceived: (e) async {
final dataIndex = e.message.indexOf('\n');
final callbackKey =
(dataIndex < 0 ? e.message : e.message.substring(0, dataIndex));
final data = (dataIndex < 0
? []
: (jsonDecode(e.message.substring(dataIndex + 1)) ?? []));
if (callbackKey == 'highcharts_flutter.chart') {
if (onLoaded != null) {
onLoaded!(this);
}
return;
}
if (HighchartsCallback.registry.containsKey(callbackKey)) {
HighchartsCallback.registry[callbackKey]!(data);
return;
}
if (_events.containsKey(callbackKey)) {
for (final callback in _events[callbackKey]!) {
await callback(data);
}
return;
}
if (debug) {
debugPrint('Unhandled callback: ${e.message}');
}
},
);
if (WebViewPlatform.instance is AndroidWebViewPlatform) {
webView = WebViewWidget.fromPlatformCreationParams(
params: AndroidWebViewWidgetCreationParams(
controller: webViewController.platform,
displayWithHybridComposition: true, // Fix scrolling interference
),
);
} else {
webView = WebViewWidget(controller: webViewController);
}
}