This is a follow-up to this question, asking if all this was even possible.
The WebView
package seems really dope. But so far it seems really obscure and dense to me.
Almost all of the examples I've been able to find refer to seeing other existing web pages and then altering them, but my use case was about having an empty page, in which I would use the more mature JS visual libraries to plot charts or graphs.
And it's not clear to me, but is this package about adding views for non-web environments? If it is, what about using it on Flutter Web? Maybe this is obvious for someone with experience with that package, but to those starting with it, it's not clear at all...
For example, I'm trying to implement this simple D3.js example, and, in the package's documentation, there's this simple example:
import 'dart:io';
import 'package:webview_flutter/webview_flutter.dart';
class WebViewExample extends StatefulWidget {
@override
WebViewExampleState createState() => WebViewExampleState();
}
class WebViewExampleState extends State<WebViewExample> {
@override
void initState() {
super.initState();
// Enable virtual display.
if (Platform.isAndroid) WebView.platform = AndroidWebView();
}
@override
Widget build(BuildContext context) {
return WebView(
initialUrl: 'https://flutter.dev',
);
}
}
I don't know what I would do for WebView.platform
in the case of Web, there's no option for it. And, when I try it on Chrome, I get — I used Chrome on Linux, and the rest of my app does work —:
The following UnsupportedError was thrown building WebView(dirty, state: _WebViewState#2d89e):
Unsupported operation: Trying to use the default webview implementation for TargetPlatform.linux
but there isn't a default one
I did try other variations of the code above, including trying to make it a StatelessWidget
without initState
, but the result was the same:
class WebViewExample extends StatelessWidget {
const WebViewExample({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: WebView(
initialUrl: 'https://flutter.dev',
),
);
}
}
Is anyone able to pull off the simple D3.js example I mentioned on Flutter Web (even better if you could send the data from Dart to JS...)? That would be of great help.