Community WebView Plugin - Allows Flutter to communicate with a native WebView.

Overview

Flutter Community: flutter_webview_plugin

NOTICE

We are working closely with the Flutter Team to integrate all the Community Plugin features in the Official WebView Plugin. We will try our best to resolve PRs and Bugfixes, but our priority right now is to merge our two code-bases. Once the merge is complete we will deprecate the Community Plugin in favor of the Official one.

Thank you for all your support, hopefully you'll also show it for Official Plugin too.

Keep Fluttering!

Flutter WebView Plugin

pub package

Plugin that allows Flutter to communicate with a native WebView.

Warning: The webview is not integrated in the widget tree, it is a native view on top of the flutter view. You won't be able see snackbars, dialogs, or other flutter widgets that would overlap with the region of the screen taken up by the webview.

The getSafeAcceptedType() function is available only for minimum SDK of 21. eval() function only supports SDK of 19 or greater for evaluating Javascript.

Getting Started

For help getting started with Flutter, view our online documentation.

iOS

In order for plugin to work correctly, you need to add new key to ios/Runner/Info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>

NSAllowsArbitraryLoadsInWebContent is for iOS 10+ and NSAllowsArbitraryLoads for iOS 9.

How it works

Launch WebView Fullscreen with Flutter navigation

new MaterialApp(
      routes: {
        "/": (_) => new WebviewScaffold(
          url: "https://www.google.com",
          appBar: new AppBar(
            title: new Text("Widget webview"),
          ),
        ),
      },
    );

Optional parameters hidden and initialChild are available so that you can show something else while waiting for the page to load. If you set hidden to true it will show a default CircularProgressIndicator. If you additionally specify a Widget for initialChild you can have it display whatever you like till page-load.

e.g. The following will show a read screen with the text 'waiting.....'.

return new MaterialApp(
  title: 'Flutter WebView Demo',
  theme: new ThemeData(
    primarySwatch: Colors.blue,
  ),
  routes: {
    '/': (_) => const MyHomePage(title: 'Flutter WebView Demo'),
    '/widget': (_) => new WebviewScaffold(
      url: selectedUrl,
      appBar: new AppBar(
        title: const Text('Widget webview'),
      ),
      withZoom: true,
      withLocalStorage: true,
      hidden: true,
      initialChild: Container(
        color: Colors.redAccent,
        child: const Center(
          child: Text('Waiting.....'),
        ),
      ),
    ),
  },
);

FlutterWebviewPlugin provide a singleton instance linked to one unique webview, so you can take control of the webview from anywhere in the app

listen for events

final flutterWebviewPlugin = new FlutterWebviewPlugin();

flutterWebviewPlugin.onUrlChanged.listen((String url) {

});

Listen for scroll event in webview

final flutterWebviewPlugin = new FlutterWebviewPlugin();
flutterWebviewPlugin.onScrollYChanged.listen((double offsetY) { // latest offset value in vertical scroll
  // compare vertical scroll changes here with old value
});

flutterWebviewPlugin.onScrollXChanged.listen((double offsetX) { // latest offset value in horizontal scroll
  // compare horizontal scroll changes here with old value
});

Note: Do note there is a slight difference is scroll distance between ios and android. Android scroll value difference tends to be larger than ios devices.

Hidden WebView

final flutterWebviewPlugin = new FlutterWebviewPlugin();

flutterWebviewPlugin.launch(url, hidden: true);

Close launched WebView

flutterWebviewPlugin.close();

Webview inside custom Rectangle

final flutterWebviewPlugin = new FlutterWebviewPlugin();

flutterWebviewPlugin.launch(url,
  fullScreen: false,
  rect: new Rect.fromLTWH(
    0.0,
    0.0,
    MediaQuery.of(context).size.width,
    300.0,
  ),
);

Injecting custom code into the webview

Use flutterWebviewPlugin.evalJavaScript(String code). This function must be run after the page has finished loading (i.e. listen to onStateChanged for events where state is finishLoad).

If you have a large amount of JavaScript to embed, use an asset file. Add the asset file to pubspec.yaml, then call the function like:

Future<String> loadJS(String name) async {
  var givenJS = rootBundle.loadString('assets/$name.js');
  return givenJS.then((String js) {
    flutterWebViewPlugin.onStateChanged.listen((viewState) async {
      if (viewState.type == WebViewState.finishLoad) {
        flutterWebViewPlugin.evalJavascript(js);
      }
    });
  });
}

Accessing local files in the file system

Set the withLocalUrl option to true in the launch function or in the Webview scaffold to enable support for local URLs.

Note that, on iOS, the localUrlScope option also needs to be set to a path to a directory. All files inside this folder (or subfolder) will be allowed access. If ommited, only the local file being opened will have access allowed, resulting in no subresources being loaded. This option is ignored on Android.

Ignoring SSL Errors

Set the ignoreSSLErrors option to true to display content from servers with certificates usually not trusted by the Webview like self-signed certificates.

Warning: Don't use this in production.

Note that on iOS, you need to add new key to ios/Runner/Info.plist

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
</dict>

NSAllowsArbitraryLoadsInWebContent is for iOS 10+ and NSAllowsArbitraryLoads for iOS 9. Otherwise you'll still not be able to display content from pages with untrusted certificates.

You can test your ignorance if ssl certificates is working e.g. through https://self-signed.badssl.com/

Webview Events

  • Stream<Null> onDestroy
  • Stream<String> onUrlChanged
  • Stream<WebViewStateChanged> onStateChanged
  • Stream<double> onScrollXChanged
  • Stream<double> onScrollYChanged
  • Stream<String> onError

Don't forget to dispose webview flutterWebviewPlugin.dispose()

Webview Functions

Future<Null> launch(String url, {
    Map<String, String> headers: null,
    Set<JavascriptChannel> javascriptChannels: null,
    bool withJavascript: true,
    bool clearCache: false,
    bool clearCookies: false,
    bool hidden: false,
    bool enableAppScheme: true,
    Rect rect: null,
    String userAgent: null,
    bool withZoom: false,
    bool displayZoomControls: false,
    bool withLocalStorage: true,
    bool withLocalUrl: true,
    String localUrlScope: null,
    bool withOverviewMode: false,
    bool scrollBar: true,
    bool supportMultipleWindows: false,
    bool appCacheEnabled: false,
    bool allowFileURLs: false,
    bool useWideViewPort: false,
    String invalidUrlRegex: null,
    bool geolocationEnabled: false,
    bool debuggingEnabled: false,
    bool ignoreSSLErrors: false,
});
Future<String> evalJavascript(String code);
Future<Map<String, dynamic>> getCookies();
Future<Null> cleanCookies();
Future<Null> resize(Rect rect);
Future<Null> show();
Future<Null> hide();
Future<Null> reloadUrl(String url);
Future<Null> close();
Future<Null> reload();
Future<Null> goBack();
Future<Null> goForward();
Future<Null> stopLoading();
Future<bool> canGoBack();
Future<bool> canGoForward();
Comments
  • Can not open url in iOS

    Can not open url in iOS

    I try to open url in Android using Flutter Webview Plugin and it works, but in iOS simulator it doesn't work. For example: I open google.com and then I search a website, I can not open the site by clicking it in google search list. Please help to resolve this..

    opened by gunadharma 19
  • Does not scroll when keyboard is appeared on focus of text field

    Does not scroll when keyboard is appeared on focus of text field

    I do Instagram implicit authentification and show login page in webview_plagin using WebViewScaffold. Page is short, so no scroll. When focus on any text field (username and password) keyboard are appeared and I can not see input field anymore.

    Is there a way to add a scrolling?

    bug 
    opened by marica27 14
  • MissingPluginException(No implementation found for method close on channel flutter_webview_plugin)

    MissingPluginException(No implementation found for method close on channel flutter_webview_plugin)

    I am trying to have WebView in Flutter using WebviewScaffold widget.

    I have installed flutter_webview_plugin: "^0.1.0+1"

    but I am getting ERROR: MissingPluginException(No implementation found for method close on channel flutter_webview_plugin) . . . MissingPluginException(No implementation found for method launch on channel flutter_webview_plugin) . . .

    Below is how my page looks like:

    import 'package:flutter/material.dart';
    import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
    
    
    class BulkProductUpdatePageRoute extends MaterialPageRoute {
      BulkProductUpdatePageRoute():
          super(builder: (BuildContext context) => new BulkProductUpdatePage());
    }
    
    class BulkProductUpdatePage extends StatefulWidget {
      @override
      _BulkProductUpdatePageState createState() => new _BulkProductUpdatePageState();
    }
    
    class _BulkProductUpdatePageState extends State<BulkProductUpdatePage> {
    
      @override
      Widget build(BuildContext context) {
        return new WebviewScaffold(
          appBar: new AppBar(
            leading: new RetailAppBarLeading(),
            title: new Text('Bulk Product Update'),
            bottom: appBarBottom(
              child: new Container(
                child: new TextField(
                  decoration: new InputDecoration(
                      icon: new Icon(
                        Icons.search,
                        color: Colors.grey,
                      ),
                      hideDivider: true,
                      hintText: 'Search Products'
                  ),
                ),
                padding: new EdgeInsets.only(
                    bottom: 5.0
                ),
              ),
            ),
          ),
          url: 'https://pub.dartlang.org/packages/flutter_webview_plugin#-installing-tab-',
        );
      }
    }
    
    
    bug 
    opened by arnoldparge 14
  • How to clear cookies (iOS)

    How to clear cookies (iOS)

    The options clearCookies work perfectly on Android but not working on iOS

    webview.launch(
        "https://google.com",
        clearCache: true,
        clearCookies: true,
    );
    
    waiting for feedback 
    opened by hungps 13
  • Webview crashes on url change on iOS

    Webview crashes on url change on iOS

    I'm getting the following error while trying to use the webview on iOS (via the Simulator) which is crashing the app. It only seems to happen for some URLs. On Android everything works fine, but on iOS I'm able to get through the login prompt and oAuth acceptance pages, but then it crashes when it tries to navigate to the actual authenticated app.

    Unsupported value: <FlutterError: 0x60800023b740> of type FlutterError
    *** First throw call stack:
    (
    	0   CoreFoundation                      0x000000010dff51e6 __exceptionPreprocess + 294
    	1   libobjc.A.dylib                     0x000000010d68a031 objc_exception_throw + 48
    	2   CoreFoundation                      0x000000010dffa472 +[NSException raise:format:arguments:] + 98
    	3   Foundation                          0x000000010d12d652 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    	4   Flutter                             0x000000010b89a808 -[FlutterStandardWriter writeValue:] + 2091
    	5   Flutter                             0x000000010b89ae52 -[FlutterStandardMethodCodec encodeMethodCall:] + 136
    	6   Flutter                             0x000000010b8945dc -[FlutterMethodChannel invokeMethod:arguments:] + 58
    	7   flutter_webview_plugin              0x000000010d052b62 -[FlutterWebviewPlugin webView:didFailNav<…>
    Lost connection to device.
    
    opened by jimsimon 13
  • Won't load on release

    Won't load on release

    For some reason when I do a simple flutterWebviewPlugin.launch for release it does not work, but a regular build (debug) does. I am sure I am missing something simple. Any ideas?

    opened by bagintz 12
  • Remove the appbar???

    Remove the appbar???

    When I launch webview in flutter, I don't need the appbar (back button and the title). How can I remove it?

    image Seem like this is the arguments for function "launch", but I can't use it as well.. Thanks you guys.

    opened by jackphuongvu 10
  • Receiving Cookies in WebView

    Receiving Cookies in WebView

    I was wondering, if it is possible to get data from cookies, set in the web view, to the flutter application. My use case is a custom auth mechanism which works by authentication with google on server side and sending a cookie with the client credentials in a cookie to the frontend (in this case my flutter app). Is this possible with this plugin?

    I saw both #7 and #8 and am not sure about this approach because of the cookie instead of a redirect url and query parameters.

    enhancement IOS ANDROID 
    opened by r-wittmann 10
  • Permissions Location android

    Permissions Location android

    Hello, im need the location permission on my web view, i have a button to request this permission, in the browser work fine but in the webview no work, the pop-up with permission not shows, i added location permission in AndroidManifest.xml but nothing happened, can help me with this?

    enhancement help wanted IOS ANDROID 
    opened by mgdecondux 9
  • Add support for sending data from webview to native in iOS and Android

    Add support for sending data from webview to native in iOS and Android

    • create the local http-server in example/html folder (for example: by http-server)
    • modify the messageUrl in main.dart to your http-server url
    • run the example project and click the Open Webview (message demo)button
    • click send to flutter button in webview and you can see the result in the bottom.
    opened by OPY-bbt 9
  • enable Javascript in iOS, support abort loading specific URLs

    enable Javascript in iOS, support abort loading specific URLs

    I create this pull request to give WebView few features:

    • enable Javascript in iOS.
    • support abort loading specific URLs by using regex pattern. Native webview in Android and iOS will use this regex to determine to continue or abort loading an URL in method shouldOverrideUrlLoading in Android and webView:decidePolicyForNavigationAction:decisionHandler in iOS
    opened by hnvn 9
  • IOS goes to live broadcast instead of camera on video recording

    IOS goes to live broadcast instead of camera on video recording

    I'm using the flutter_webview_plugin package to show our website as a web view in our Flutter iOS app. The website supports video recording, and everything works fine on the web.

    Whenever the user starts recording video from the app, it accidentally redirects them to live broadcast instead of the camera.

    ezgif com-gif-maker-4

    Why is that happen?

    Check out our discussion on StackOverflow

    flutter doctor:

    [✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-x64, locale en-IL)
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    [✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2021.2)
    [✓] VS Code (version 1.73.1)
    [✓] Connected device (2 available)
    [✓] HTTP Host Availability
    

    IOS version: 15.2.1

    opened by CartmanGD 0
  •  deprecated version

    deprecated version

    he plugin flutter_webview_plugin uses a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.

    paste it here...
    

    Steps to Reproduce

    1. ...
    2. ...
    3. ...

    Logs

    opened by paulobreim 0
  • Is it possible to load and display Three.js content in Flutter Web Application ?

    Is it possible to load and display Three.js content in Flutter Web Application ?

    Hi Hope you are doing good. I have one requirement. Is it possible to load and display Three.js content in Flutter Web Application. Also I want interactions with JS to Flutter and Flutter to JS. There is multiple plugins are there to load web URL in Flutter Mobile App. I don't need for mobile.

    opened by suryanadiminti99 0
Releases(0.3.11)
  • 0.3.11(Apr 7, 2020)

  • 0.3.10(Dec 11, 2019)

  • 0.3.9+1(Nov 15, 2019)

  • 0.3.9(Nov 14, 2019)

    • Fixed error methods on iOS
    • fixed build
    • fixed ios clean cookies
    • 4 Make plugin work in headless mode when extending FlutterApplication
    • added canGoBack and canGoForward methods
    Source code(tar.gz)
    Source code(zip)
  • 0.3.8(Sep 13, 2019)

    • Fix iOS local URL support (fixes #114)
    • bugfix: Added google() repository to allprojects to satisfy androidx build rules
    • fixed min sdk for android
    Source code(tar.gz)
    Source code(zip)
  • 0.3.7(Aug 15, 2019)

  • 0.3.6(Aug 15, 2019)

    • Allow web contents debugging in Chrome
    • Android: allow geolocation and file chooser simultaneously
    • Add min sdk requirement and descriptions
    • fix bug android webview httperror exception
    • Exposes displayZoomControls, withOverviewMode and useWideViewPort settings for Android WebView
    Source code(tar.gz)
    Source code(zip)
  • 0.3.5(May 7, 2019)

    • Ability to choose from camera or gallery when using
    • Support for webview’s estimated loading progress #255
    • Fix back button handler to be compatible with the WillPopScope widget
    Source code(tar.gz)
    Source code(zip)
  • 0.3.4(Apr 18, 2019)

  • 0.3.3(Mar 28, 2019)

  • 0.3.2(Mar 28, 2019)

  • 0.3.1(Mar 17, 2019)

    Fixed / merged issues:

    • Add support for geolocation Android
    • fix No269: Can't load target="_blank" links on iOS
    • fix: reloadUrl will not return Future
    • Fix height of keyboard
    • Fix Hide/Show WebView
    • hotfix widget back to initialChild after webview is tapped on Android
    Source code(tar.gz)
    Source code(zip)
Owner
Flutter Community
A central place for all community made Flutter packages. To get started, see the README of the 'community' repository.
Flutter Community
A Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed apps.

Flutter AppAvailability Plugin A Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed a

Lorenzo Pichilli 89 Dec 2, 2022
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

On most operating systems, permissions aren't just granted to apps at install time. Rather, developers have to ask the user for permissions while the

Baseflow 1.7k Jan 3, 2023
File picker plugin for Flutter, compatible with both iOS & Android and desktop (go-flutter).

File Picker A package that allows you to use the native file explorer to pick single or multiple files, with extensions filtering support. Currently s

Miguel Ruivo 985 Jan 5, 2023
Plugin to access VPN service for Flutter | Flutter 的 VPN 插件

Flutter VPN plugin This plugin help developers to access VPN service in their flutter app. 本插件帮助开发者在自己的应用内调用 VPN 服务。 The Android part was implemented

Xdea 277 Dec 28, 2022
A Flutter plugin to easily handle realtime location in iOS and Android. Provides settings for optimizing performance or battery.

Flutter Location Plugin This plugin for Flutter handles getting location on Android and iOS. It also provides callbacks when location is changed. Gett

Guillaume Bernos 953 Dec 22, 2022
Flutter geolocation plugin for Android and iOS.

geolocation Flutter geolocation plugin for Android API 16+ and iOS 9+. Features: Manual and automatic location permission management Current one-shot

Loup 221 Dec 27, 2022
A Flutter plugin for displaying local notifications on Android, iOS and macOS

Flutter Local Notifications plugin This repository consists hosts the following packages flutter_local_notifications: code for the cross-platform faci

Michael Bui 2.1k Dec 30, 2022
Flutter Downloader - A plugin for creating and managing download tasks. Supports iOS and Android. Maintainer: @hnvn

Flutter Downloader A plugin for creating and managing download tasks. Supports iOS and Android. This plugin is based on WorkManager in Android and NSU

Flutter Community 789 Jan 3, 2023
Android and iOS Geolocation plugin for Flutter

Flutter Geolocator Plugin A Flutter geolocation plugin which provides easy access to platform specific location services (FusedLocationProviderClient

Baseflow 1k Jan 5, 2023
Flutter Plugin for AR (Augmented Reality) - Supports ARKit on iOS and ARCore on Android devices

ar_flutter_plugin Flutter Plugin for AR (Augmented Reality) - Supports ARKit for iOS and ARCore for Android devices. Many thanks to Oleksandr Leuschen

Lars Carius 222 Jan 4, 2023
A lightweight Flutter plugin for making payments and printing on MyPos

my_poster ?? my_poster is in beta - please provide feedback (and/or contribute) if you find issues ??️ A lightweight Flutter plugin for making payment

Antonio Mentone 3 Oct 10, 2022
Telegram stickers importing Flutter plugin for iOS and Android

TelegramStickersImport — Telegram stickers importing Flutter plugin for iOS and Android TelegramStickersImport helps your users import third-party pro

Iurii Dorofeev 20 Dec 3, 2022
Plugin to retrieve a persistent UDID across app reinstalls on iOS and Android.

flutter_udid Plugin to retrieve a persistent UDID across app reinstalls on iOS and Android. Getting Started import 'package:flutter_udid/flutter_udid.

Leon Kukuk 183 Dec 21, 2022
Flutter library for iOS Widgets Extensions. Integrate a Widget into your App 🍏📱

flutter_widgetkit Flutter Library for the iOS ?? WidgetKit framework and Widget Communication Table of Contents ?? Introduction ??‍?? Installation ??‍

Fasky 227 Dec 31, 2022
Community WebView Plugin - Allows Flutter to communicate with a native WebView.

NOTICE We are working closely with the Flutter Team to integrate all the Community Plugin features in the Official WebView Plugin. We will try our bes

Flutter Community 1.4k Dec 22, 2022
Plugin that allow Flutter to communicate with a native WebView.

interactive_webview Plugin that allow Flutter to communicate with a native WebView. Warning: This is not a display WebView. This plugin is designed to

Duy Duong 46 Dec 15, 2022
A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.

Flutter InAppWebView Plugin A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser windo

Lorenzo Pichilli 2.3k Jan 8, 2023
Flutter Community - A central place for community made Flutter content.

Flutter Community A central place for community made Flutter content. The Flutter Community is an organization aimed at providing a central place for

Flutter Community 1.3k Jan 1, 2023
Pensil Community official Flutter SDK. Build your own community experience using Dart and Flutter.

Official flutter package for Pensil The official Dart client for Pensil communities, a service for building communites applications. This library can

Pensil Inc 6 Oct 6, 2022
A Flutter plugin that allows you to add an inline WebView.

native_webview A Flutter plugin that allows you to add an inline WebView. Motivation There is already a useful library for working with WebViews in Fl

hisaichi5518 46 Dec 14, 2022