Flutter Web view not loading in windows desktop application

Viewed 5889
Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: WebView(
        initialUrl: "https://www.google.com/",
        onWebViewCreated: (WebViewController webViewController) {
          _controller.complete(webViewController);
        },
      ),
    );
  }

This is my code snippet how to resolve this issue

2 Answers

While waiting for the official support from Flutter team, you can use flutter-webview-windows package. It adds support for Windows webview on Flutter and can communicate between the webview and flutter app (more detail here).

final _controller = WebviewController();

@override
void initState() {
  super.initState();
  _init();
}

void _init() async {
  await _controller.initialize();
  await _controller.loadUrl('https://flutter.dev');

  if (!mounted) return;
  setState(() {});
}

@override
void dispose() {
  super.dispose();
  _controller.dispose();
}

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(title: const Text('Webview')),
    body: _controller.value.isInitialized
        ? Webview(_controller)
        : const Text('Not Initialized'),
  );
}

The webview_flutter plugin doesn't exist for Windows yet, and in fact isn't possible to write yet since PlatformView support isn't implemented for Windows. (As the documentation says: "there are currently few plugins that actually have desktop support".)

Currently if you want a web view in your application it would need to be in a separate window, and you would need to write a plugin that creates and managers that Windows and web view.

Related