Um WebView multiplataforma com recursos avançados, usando webview_flutter para dispositivos móveis e iframe para a web. Pronto para interoperabilidade com JS.
Orientação gerada a partir de informações públicas. Apenas para referência.
webviewx é um pacote de webview multiplataforma que utiliza webview_flutter para Android e iOS, e iframe para a web, oferecendo uma API consistente entre plataformas. Ele suporta interoperação com JavaScript, permitindo comunicação sem problemas entre Dart e o conteúdo da web. Projetado para desenvolvedores que buscam uma solução unificada para incorporar conteúdo da web em aplicativos Flutter com funcionalidades ricas e compatibilidade com plataformas.
Casos de uso
Incorporar conteúdo da web em aplicativos móveis
Integrar formulários ou painéis baseados na web
Habilitar o desenvolvimento de aplicativos híbridos com componentes da web
Suporte para carregamento dinâmico de conteúdo a partir de URLs
Criando recursos embutidos em web em aplicativos Flutter
Principais recursos
Suporte multiplataforma (Android, iOS, Web)
Capacidade de interoperabilidade com JavaScript
Usa WebView nativo no móvel e iframe na web
API consistente entre plataformas
Leve e fácil integração
Indicado para
Desenvolvedores de aplicativos híbridos Flutter
Equipes que precisam de incorporação de conteúdo da web
Projetos que exigem comunicação JS com visualizações da web
Aplicativos destinados a múltiplas plataformas com lógica de interface compartilhada
Prototipar recursos integrados à web rapidamente
Considerações
A plataforma web usa iframe, o que pode limitar alguns recursos avançados do webview
Requer um manuseio cuidadoso da segurança ao carregar conteúdo externo
Personalização limitada em comparação com implementações nativas de WebView
Pode ser necessário configuração adicional para interações web complexas
Depende do webview_flutter para dispositivos móveis, que possui suas próprias restrições
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
This package has been deprecated
A feature-rich cross-platform webview using webview_flutter for mobile and iframe for web. JS interop-ready.
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