A cross-platform WebView for Android, iOS and Web.

Overview

webviewx

A feature-rich cross-platform webview using webview_flutter for mobile and iframe for web. JS interop-ready.

Getting started


Gallery

Mobile

Web


Basic usage

1. Create a WebViewXController inside your stateful widget

late WebViewXController webviewController;

2. Add the WebViewX widget inside the build method, and set the onWebViewCreated callback in order to retrieve the controller when the webview is initialized

WebViewX(
    initialContent: '<h2> Hello, world! </h2>',
    initialSourceType: SourceType.HTML,
    onWebViewCreated: (controller) => webviewController = controller,
    ...
    ... other options
);

Important !

If you need to add other widgets on top of the webview (e.g. inside a Stack widget), you MUST wrap those widgets with a WebViewAware widget. This does nothing on mobile, but on web it allows widgets on top to intercept gestures. Otherwise, those widgets may not be clickable and/or the iframe will behave weird (unexpected refresh/reload - this is a well known issue).

Also, if you add widgets on top of the webview, wrap them and then you notice that the iframe still reloads unexpectedly, you should check if there are other widgets that sit on top without being noticed, or try to wrap InkWell, GestureRecognizer or Button widgets to see which one causes the problem.

3. Interact with the controller (run the example app to check out some use cases)

webviewController.loadContent(
    'https://flutter.dev',
    SourceType.url,
);
webviewController.goBack();

webviewController.goForward();
...
...

Features

Note: For more detailed information about things such as EmbeddedJsContent, please visit each own's .dart file from the utils folder.

  • Widget properties

Feature Details
String initialContent Initial webview content
SourceType initialSourceType Initial webview content type (url, urlBypass or html)
String? userAgent User agent
double width Widget's width
double height Widget's height
Function(WebViewXController controller)? onWebViewCreated Callback that gets executed when the webview has initialized
Set<EmbeddedJsContent> jsContent A set of EmbeddedJsContent, which is an object that defines some javascript which will be embedded in the page, once loaded (check the example app)
Set<DartCallback> dartCallBacks A set of DartCallback, which is an object that defines a dart callback function, which will be called from javascript (check the example app)
bool ignoreAllGestures Boolean value that specifies if the widget should ignore all gestures right after it is initialized
JavascriptMode javascriptMode This specifies if Javascript should be allowed to execute, or not (allowed by default, you must allow it in order to use above features)
AutoMediaPlaybackPolicy initialMediaPlaybackPolicy This specifies if media content should be allowed to autoplay when initialized (i.e when the page is loaded)
void Function(String src)? onPageStarted Callback that gets executed when a page starts loading (e.g. after you change the content)
void Function(String src)? onPageFinished Callback that gets executed when a page finishes loading
NavigationDelegate? navigationDelegate Callback that, if not null, gets executed when the user clicks something in the webview (on Web it only works for SourceType.urlBypass, for now)
void Function(WebResourceError error)? onWebResourceError Callback that gets executed when there is an error when loading resources issues on web
WebSpecificParams webSpecificParams This is an object that contains web-specific options. Theese are not available on mobile (yet)
MobileSpecificParams mobileSpecificParams This is an object that contains mobile-specific options. Theese are not available on web (yet)

  • Controller properties

Feature Usage
Load URL that allows iframe embedding webviewController.loadContent(URL, SourceType.URL)
Load URL that doesnt allow iframe embedding webviewController.loadContent(URL, SourceType.URL_BYPASS)
Load URL that doesnt allow iframe embedding, with headers webviewController.loadContent(URL, SourceType.URL_BYPASS, headers: {'x-something': 'value'})
Load HTML from string webviewController.loadContent(HTML, SourceType.HTML)
Load HTML from assets webviewController.loadContent(HTML, SourceType.HTML, fromAssets: true)
Check if you can go back in history webviewController.canGoBack()
Go back in history webviewController.goBack()
Check if you can go forward in history webviewController.canGoForward()
Go forward in history webviewController.goForward()
Reload current content webviewController.reload()
Check if all gestures are ignored webviewController.ignoringAllGestures
Set ignore all gestures webviewController.setIgnoreAllGestures(value)
Evaluate "raw" javascript code webviewController.evalRawJavascript(JS)
Evaluate "raw" javascript code in global context ("page") webviewController.evalRawJavascript(JS, inGlobalContext: true)
Call a JS method webviewController.callJsMethod(METHOD_NAME, PARAMS_LIST)
Retrieve webview's content webviewController.getContent()
Get scroll position on X axis webviewController.getScrollX()
Get scroll position on Y axis webviewController.getScrollY()
Scrolls by x on X axis and by y on Y axis webviewController.scrollBy(int x, int y)
Scrolls exactly to the position (x, y) webviewController.scrollTo(int x, int y)
Retrieves the inner page title webviewController.getTitle()
Clears cache webviewController.clearCache()

Contribution

Any help from the open-source community is always welcome and needed:

  • Found an issue?

    • Please fill a bug report with details.
  • Wish a feature?

    • Open a feature request with use cases.
  • Are you using and liking the project?

    • Promote the project: create an article, do a post or make a donation.
  • Are you a developer?

    • Fix a bug and send a pull request.
    • Implement a new feature.
  • Have you already helped in any way?

    • Many thanks from me, the contributors and everybody that uses this project!

Credits

This package has updated the webviewx code and fixed a few issues as it isn't remain updated.

You might also like...

A cross-platform Flutter home workout app that respects your privacy. THIS IS A GITLAB MIRROR, file issues and contribute there.

A cross-platform Flutter home workout app that respects your privacy. THIS IS A GITLAB MIRROR, file issues and contribute there.

Feeel Feeel is an open-source workout app for doing simple at-home exercises. This is a rewrite of the original app in Flutter, to make development ea

Dec 26, 2022

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.

nfc_in_flutter NFC in Flutter is a plugin for reading and writing NFC tags in Flutter. It works on both Android and iOS with a simple stream interface

Sep 28, 2022

Flutter-for-Wordpress-App - Cross platform wordpress news app built with Flutter and WP REST API

Flutter-for-Wordpress-App - Cross platform wordpress news app built with Flutter and WP REST API

Flutter for Wordpress A flutter app for a wordpress websites with clean and elegant design. This app is available in free and pro version. You can cho

Dec 23, 2022

UIWidget is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps.

UIWidget is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps.

⚠️ The main repository of UIWidgets has been moved to https://github.com/Unity-Technologies/com.unity.uiwidgets. Please visit the new site if you have

Dec 27, 2022

Open source cross-platform client for popular imageboards: 4chan.org and 2ch.hk

Open source cross-platform client for popular imageboards: 4chan.org and 2ch.hk

iChan (iOS) and Zchan (Android) Open source cross-platform client for popular im

Dec 31, 2022

Time-Tracker is a cross platform software integrated with Firebase and this is the mobile version created with Flutter.

Time-Tracker is a cross platform software integrated with Firebase and this is the mobile version created with Flutter.

Time Tracker | Flutter Time tracker is a cloud based task manager where you can manage your tasks in your mobile or web browser in a same time or in a

Oct 25, 2022

A cross-platform classic and minimalist logger written in the Dart language.

A cross-platform classic and minimalist logger written in the Dart language.

A cross-platform classic and minimalist logger written in the Dart language.

Dec 3, 2022

Flutter Download Manager is a Cross-Platform file downloader with Parallel and Batch Download support

Flutter Download Manager is a Cross-Platform file downloader with Parallel and Batch Download support

Flutter Download Manager is a Cross-Platform file downloader with Parallel and Batch Download support. Manage download tasks by url and be notified of status and their progress. Pause, Cancel, Queue and Resume Downloads.

Dec 17, 2022

Blood Bank is cross platform mobile application that is developed using technologies like Flutter/Dart for frontend and Firebase for data storage

Blood Bank is cross platform mobile application that is developed using technologies like Flutter/Dart for frontend and Firebase for data storage

Blood Bank is cross platform mobile application that is developed using technologies like Flutter/Dart for frontend and Firebase for data storage. The sole goal of this application is to make blood donation resourceful and accessible all round the world.

Nov 5, 2022
Comments
  • Refused to display 'https://xxxxx' in a frame because it set 'X-Frame-Options' to 'deny'.

    Refused to display 'https://xxxxx' in a frame because it set 'X-Frame-Options' to 'deny'.

    I am calling the payment website, getting Refused to display because of 'X-Frame-Options' to 'deny'.

    webviewx_plus: ^0.3.2

    WebViewX( height: Get.height, width: Get.width, javascriptMode: JavascriptMode.unrestricted, initialSourceType: SourceType.urlBypass, initialContent: "https://xxxxxxurl", onWebResourceError: (WebResourceError webResource) { log("webResource.description : ${webResource.description}"); log("webResource.errorCode : ${webResource.errorCode}"); log("webResource.errorType : ${webResource.errorType}"); }, onPageStarted: (String url) { print('Page started loading: $url}'); }, onPageFinished: (String url) async {}, navigationDelegate: (NavigationRequest request) async { return NavigationDecision.navigate; }, )

    opened by altafkhan8719 2
Owner
Mahad Asghar
Mahad Asghar
Aditya 93 Dec 25, 2022
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

Flutter permission_handler plugin The Flutter permission_handler plugin is build following the federated plugin architecture. A detailed explanation o

Baseflow 1.7k Dec 31, 2022
Cross Platform app in Flutter with Firebase Auth and Firestore. Available for Mobile,Web,Desktop

NavokiNotes Navoki Notes, a note app app, will sync data to cloud and on all devices. We have application for Android, iOS, Web App, PWA, Windows, mac

shivam srivastava 93 Dec 27, 2022
A beautiful cross platform mobile web app use this and ENJOY (2 page) - Flutter UI from scratch

course_app 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

Mobin 2 Feb 9, 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
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 complete tutorial series on Flutter webview.

Flutter Webview | Tech With Sam Flutter Webview Tutorial - Watch on youtube ✌   App Preview App Screenshot App Screenshot A new Flutter project. Getti

Samuel Adekunle 43 Dec 30, 2022
Tech News Application by Flutter WebView .

Tech News APP developed by flutter_web_view Tech News developed by Flutter (Dart) it is a simple WebView that run on Android & iOS. *New changes: Migr

Hamed Jaliliani 34 Oct 31, 2021
WooCommerce App template that uses Flutter. Integrated to work with WooCommerce stores, connect and create an IOS and Android app from Flutter for IOS and Android

WooCommerce App: Label StoreMax Label StoreMax - v5.3.1 Official WooSignal WooCommerce App About Label StoreMax Label StoreMax is an App Template for

WooSignal 314 Jan 9, 2023