Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Webview in Flutter?

I know its possible to add a WebView as a full page but couldn't find any sample code to do it. I assume you could use a PageView as it's base but not sure how to call the native android WebView and add it to the PageView.

Can anyone point me in the right direction?

like image 750
Donny V. Avatar asked Apr 27 '17 13:04

Donny V.


People also ask

How do I import WebView?

Modify src/MainActivity. java file to add WebView code. Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.


2 Answers

You can use https://pub.dartlang.org/packages/webview_flutter

example

import 'package:webview_flutter/webview_flutter.dart';  return Scaffold(       appBar: AppBar(         title: const Text('Flutter WebView example'),       ),       body: const WebView(         initialUrl: 'https://flutter.io',         javascriptMode: JavascriptMode.unrestricted,       ),     ); 
like image 73
Shyju M Avatar answered Sep 24 '22 14:09

Shyju M


Flutter doesn't have built-in support for embedded WebViews. Follow issue 730 for updates.

You can still show web content in your app, but you'll have to leave Flutter-land using the plugin system.

If you just want to open a browser, you can use the url_launcher Flutter plugin.

If you want to do something fancier (perhaps you don't want a visible address bar), you could implement a custom UIViewController (iOS example) and Activity (Android example) and use the plugin API to launch into these.

like image 23
Collin Jackson Avatar answered Sep 24 '22 14:09

Collin Jackson