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?
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?
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'),
),
),
);
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" :)
The flutter_inappwebview package just added support for the web!
You can read the web setup instructions in the official Flutter InappWebView docs but to summarize:
<head>
<!-- ... -->
<script type="application/javascript" src="/assets/packages/flutter_inappwebview/assets/web/web_support.js" defer></script>
<!-- ... -->
</head>
Scaffold(
body: SafeArea(
child: InAppWebView(
initialUrlRequest: URLRequest(url:WebUri('https://flutter.dev/')),
)
)
);
Note that there are some restrictions on what can be done in a WebView an Flutter web but for simply displaying content, this should work.