Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Webview not working for Flutter web

Tags:

flutter-web

I am trying to show a webpage in webview via URL. I have tried flutter_webview_plugin plugin but it was not working when I run the project on the browser.

Is there any another way to show the webpage in the flutter web application?

like image 317
Dhanaji Yadav Avatar asked Apr 08 '26 11:04

Dhanaji Yadav


2 Answers

flutter_webview_plugin is to embed web pages inside an app. In flutter web you should use HtmlElementView widget. Most demos out there use IFrameElement to embed a webpage. You can check this easy_web_view package for handling both mobile and web platform automatically. It internally uses HTMLElementView and WebView automatically depending on the case of the deployment.

some example is available here

Update for adding onLoad listener

IFrameElement iframeElement = IFrameElement()
      ..src = 'url'
      ..style.border = 'none'
      ..onLoad.listen((event) {
        // perform you logic here.
      });

    ui.platformViewRegistry.registerViewFactory(
      'webpage',
      (int viewId) => iframeElement,
    );

    return Directionality(
      textDirection: TextDirection.ltr,
      child: Center(
        child: SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: HtmlElementView(viewType: 'webpage'),
        ),
      ),
    );
like image 98
Abhilash Chandran Avatar answered Apr 11 '26 21:04

Abhilash Chandran


if someone facing issue loading mobile side then go with this, its works in Flutter Android, Ios, Web :-

EasyWebView(
        height: 400,
        width: 1000,
        isHtml: false, // Use Html syntax
        isMarkdown: false, // Use markdown syntax
        convertToWidgets: true,
        src: Uri.dataFromString('<html><body><iframe allow="camera *;microphone *" height="100%" width="100%"'
            ' frameborder="0" src="$url"></iframe></body></html>', mimeType: 'text/html').toString(),
      ),

you guys can use any webview to load any web page in your web/app in flutter using Url in html just change src = "$url" :)

like image 37
hio Avatar answered Apr 11 '26 20:04

hio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!