webviewx_plus 0.5.1%2B1

SDKflutter
Platformandroidiosweb

A cross-platform webview using webview_flutter for mobile and iFrame for web.

webviewx

Made with ❤️ by Cross Sonic

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

Getting started


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

FeatureDetails
String initialContentInitial webview content
SourceType initialSourceTypeInitial webview content type (url, urlBypass or html)
String? userAgentUser agent
double widthWidget's width
double heightWidget's height
Function(WebViewXController controller)? onWebViewCreatedCallback that gets executed when the webview has initialized
Set<EmbeddedJsContent> jsContentA 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> dartCallBacksA set of DartCallback, which is an object that defines a dart callback function, which will be called from javascript (check the example app)
bool ignoreAllGesturesBoolean value that specifies if the widget should ignore all gestures right after it is initialized
JavascriptMode javascriptModeThis specifies if Javascript should be allowed to execute, or not (allowed by default, you must allow it in order to use above features)
AutoMediaPlaybackPolicy initialMediaPlaybackPolicyThis specifies if media content should be allowed to autoplay when initialized (i.e when the page is loaded)
void Function(String src)? onPageStartedCallback that gets executed when a page starts loading (e.g. after you change the content)
void Function(String src)? onPageFinishedCallback that gets executed when a page finishes loading
NavigationDelegate? navigationDelegateCallback 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)? onWebResourceErrorCallback that gets executed when there is an error when loading resources issues on web
WebSpecificParams webSpecificParamsThis is an object that contains web-specific options. Theese are not available on mobile (yet)
MobileSpecificParams mobileSpecificParamsThis is an object that contains mobile-specific options. Theese are not available on web (yet)

  • Controller properties

FeatureUsage
Load URL that allows iframe embeddingwebviewController.loadContent(URL, SourceType.URL)
Load URL that doesnt allow iframe embeddingwebviewController.loadContent(URL, SourceType.URL_BYPASS)
Load URL that doesnt allow iframe embedding, with headerswebviewController.loadContent(URL, SourceType.URL_BYPASS, headers: {'x-something': 'value'})
Load HTML from stringwebviewController.loadContent(HTML, SourceType.HTML)
Load HTML from assetswebviewController.loadContent(HTML, SourceType.HTML, fromAssets: true)
Check if you can go back in historywebviewController.canGoBack()
Go back in historywebviewController.goBack()
Check if you can go forward in historywebviewController.canGoForward()
Go forward in historywebviewController.goForward()
Reload current contentwebviewController.reload()
Check if all gestures are ignoredwebviewController.ignoringAllGestures
Set ignore all gestureswebviewController.setIgnoreAllGestures(value)
Evaluate "raw" javascript codewebviewController.evalRawJavascript(JS)
Evaluate "raw" javascript code in global context ("page")webviewController.evalRawJavascript(JS, inGlobalContext: true)
Call a JS methodwebviewController.callJsMethod(METHOD_NAME, PARAMS_LIST)
Retrieve webview's contentwebviewController.getContent()
Get scroll position on X axiswebviewController.getScrollX()
Get scroll position on Y axiswebviewController.getScrollY()
Scrolls by x on X axis and by y on Y axiswebviewController.scrollBy(int x, int y)
Scrolls exactly to the position (x, y)webviewController.scrollTo(int x, int y)
Retrieves the inner page titlewebviewController.getTitle()
Clears cachewebviewController.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!

Support & Development Services

This plugin is maintained by Cross Sonic, a software solutions company specializing in Flutter, .NET, AI, and cloud-based applications.

Need Custom Development?

If you need custom development, feature enhancements, or professional support, Cross Sonic provides dedicated development services tailored to your needs. Reach out to us at contact@crosssonic.com.

License

This project is licensed under the MIT License.