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
Timy - open source mobile app for groups to communicate and organize themselves. Built with flutter.

Timy app An amazing open-source group messaging app build with flutter. ✨ Main Features Multiple groups (similar to Teams in Slack). Multiple open or

null 1.9k Dec 25, 2022
Amir Khan 47 Jan 8, 2023
Utility Manager Flutter Application is made with Flutter and Supabase which allows user to add task, set remainder to the task, set color to separate tasks and it allows to add URL with URL's informations.

Utility Manager Flutter Application! Utility Manager Flutter Application is made with Flutter and Supabase which allows user to add task, set remainde

Kathirvel Chandrasekaran 6 Jan 6, 2022
This is a Flutter project inspired by sustainability and powered by the community

This is a Flutter project inspired by sustainability and powered by the community. TrashTrack is a demo of a social platform with geolocation features that brings people a new way of collaboration.

David 0 Oct 31, 2021
It is a simple group chat application made with flutter back-end by Firebase. People can chat like a community chat.

flash_chat A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if th

Moideen Rafih P A 4 Aug 7, 2022
Pig Community Mobile Application

Hello Fellow Pigsters Pig Community Mobile Application Getting Started This project is a starting point for a Flutter application. A few resources to

null 3 May 21, 2021
Let's makeover your backyard with the power of community

Backover Let's give our backyard a makeover! ✨ 25 out of 30 people are usually pretty unhappy about how their backyard looks. Even if some people like

Betaoverflow 7 Dec 28, 2022
This is an official mobile app for community classroom

Community Classroom Mobile app This repository contains code for mobile app of community classroom. Architecture to be followed for each feature: We a

Community Classroom 60 Nov 20, 2022
Application of Community for students

small_talk An Anonymous Community for Teenage Student Getting Started This project is a starting point for a Flutter application. A few resources to g

Park Geonhyo 0 Dec 10, 2021
Actively maintained, community-driven chat UI implementation with an optional Firebase BaaS.

Flutter Chat UI Actively maintained, community-driven chat UI implementation with an optional Firebase BaaS. Flyer Chat is a platform for creating in-

Flyer Chat 662 Jan 7, 2023
Showwcase is a professional network built for developers to connect, build community, and find new opportunities.

Showwcase Generated by the Very Good CLI ?? Showwcase is a professional network built for developers to connect, build community, and find new opportu

Luis Ciber 4 Jan 13, 2022
PaperClip - A trading, community based mobile platform.

PaperClip A trading, community based mobile platform. Getting Started This project is still under development and will not be released in public. The

null 1 Mar 20, 2022
Plugin with native integration for WebSocket.

NOTE: This repository is no longer maintained by ENGAPP. It was moved to be maintained by Kunlatek on the following link: https://github.com/kunlatek/

EngApp 35 Sep 22, 2022
Flutter plugin that allows users to create TextAvatar easily!

Colorize Text Avatar Colorize Text Avatar is a package to generate avatar based on your user initials. It supports to generate avatars based on your s

Deniz Çolak 17 Dec 14, 2022
This plugin allows Flutter desktop apps to resizing and repositioning the window.

window_manager This plugin allows Flutter desktop apps to resizing and repositioning the window. window_manager Platform Support Quick Start Installat

LeanFlutter 346 Jan 3, 2023
This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).

hotkey_manager This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut). hotkey_manager Platform Support Quick Star

LeanFlutter 81 Dec 21, 2022
Plant Manager is an application that was developed on Rocketseat NLW5 with React Native but was rebuilt using Flutter.

Technologies | Project | Layout | License ?? Technologies This project was developed with the following technologies: Flutter ?? Project Plant Manager

Mayderson 7 Aug 11, 2021
This is the new version of my Task app "Tasko" which was done in Java. She is now in Flutter for the HotReload and the native Cross-Platform.

tasko_rem The Tasko App is now compatible on iOS, Android and others distribution, because it's made with Flutter ✨ You can now add task, check them o

Scythe 12 May 2, 2022
A new practical project made with Flutter and some native widgets, movie API, provider state and more.

Flutter Movie App This project was created with Flutter and some native Widgets like SingleChildScrollView, Hero Animation, SliverAppBar, StreamBuilde

Paúl 4 Jul 12, 2022