Aus öffentlichen Paketdaten erstellte Orientierung.
webviewx ist ein plattformübergreifendes WebView-Paket, das auf Android und iOS webview_flutter nutzt und für Web iframe verwendet, wodurch eine konsistente API über alle Plattformen hinweg bereitgestellt wird. Es unterstützt JavaScript-Interop und ermöglicht nahtlose Kommunikation zwischen Dart und Web-Inhalt. Entworfen für Entwickler, die eine einheitliche Lösung zur Einbettung von Webinhalten in Flutter-Anwendungen mit reichhaltigen Funktionen und Plattformkompatibilität suchen.
Anwendungsfälle
Webinhalte in mobilen Apps einbetten
Web-basierte Formulare oder Dashboards integrieren
Hybrid-App-Entwicklung mit Web-Komponenten ermöglichen
Unterstützung für dynamisches Laden von Inhalten über URLs
Web-eingebettete Funktionen in Flutter-Anwendungen erstellen
1. Create a WebViewXController inside your stateful widget
lateWebViewXController 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
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)
To make the web version (iframe) work as it is, I had to use some of the code from x-frame bypass in order to make a request to a CORS proxy, which removes the headers that block iframe embeddings.
This might seem like a hack, and it really is, but I couldn't find any other way to make the iframe behave similar to the mobile webview (which is some kind of an actual browser, that's why everything works there by default).
About Web navigation
On web, the history navigation stack is built from scratch because I couldn't handle iframe's internal history the right way.
Known issues and TODOs
[ x ] On web, user-agent and headers only work when using SourceType.urlBypass, and they only have effect the first time being used (view/web.dart)
[ x ] On web, it should be possible to send any errors caught when loading an urlBypass to a dart callback, which will then be sent through the onWebResourceError callback, just like on the mobile version (utils/x_frame_options_bypass.dart)
[ x ] On web, it should be possible to add a custom proxy list without the js null-checking mess (utils/x_frame_options_bypass.dart)
[ ? ] Eventually (if possible), most if not all properties from WebSpecificParams and MobileSpecificParams should merge and theese two objects may disappear
[ x ] On mobile, the controller's value's source type becomes out of sync when moving back and forth in history. This happens because the url change is not yet intercepted and set the model accordingly (shouldn't be hard to fix).
[ ] On mobile, the controller's callJsMethod doesnt throw an error if the operation failed. Instead it only shows the error in console.
[ ] Add tests
List open, there may be others
Credits
This package wouldn't be possible without the following:
x-frame-bypass for allowing the iframe to bypass websites' X-Frame-Options: deny/same-origin headers, thus allowing us to load any webpage (just like on mobile)
https://cors.bridged.cc/ for the free CORS proxy
https://api.codetabs.com/ for the free CORS proxy
And last but not least, http://deversoft.ro (the company I work for) for motivating me throughout the development process