Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Web view not loading in windows desktop application

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

like image 368
Joel jones Avatar asked Sep 05 '25 02:09

Joel jones


1 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'),
  );
}
like image 169
NearHuscarl Avatar answered Sep 07 '25 19:09

NearHuscarl