webviewx는 Android 및 iOS에서 webview_flutter를 사용하고 웹에서는 iframe을 활용하는 크로스플랫폼 웹뷰 패키지로, 플랫폼 간 일관된 API를 제공합니다. JavaScript 상호운용을 지원하여 Dart와 웹 콘텐츠 간의 원활한 통신이 가능합니다. Flutter 앱에 웹 콘텐츠를 삽입하고 풍부한 기능과 플랫폼 호환성을 갖춘 통합 솔루션을 찾는 개발자를 위한 것입니다.
사용 사례
모바일 앱에 웹 콘텐츠 삽입
웹 기반 양식 또는 대시보드 통합
웹 컴포넌트를 사용한 하이브리드 앱 개발 활성화
URL에서 동적 콘텐츠를 로드하는 것을 지원
Flutter 앱에서 웹 임베드 기능 구축하기
주요 기능
크로스 플랫폼 지원 (Android, iOS, Web)
자바스크립트 상호 운용 기능
모바일에서는 네이티브 웹뷰를, 웹에서는 iframe을 사용
플랫폼 간 일관된 API
경량이며 간편한 통합
적합한 대상
하이브리드 플러터 앱을 개발하는 개발자
웹 콘텐츠 삽입이 필요한 팀
웹 뷰와의 JS 통신이 필요한 프로젝트
공유 UI 로직을 가진 다중 플랫폼 앱
웹 통합 기능을 빠르게 프로토타이핑하기
고려 사항
웹 플랫폼은 iframe를 사용하며, 일부 고급 웹뷰 기능이 제한될 수 있습니다
외부 콘텐츠를 로드할 때 보안을 신중하게 다뤄야 합니다
네이티브 웹뷰 구현과 비교하여 사용자 정의가 제한적입니다
복잡한 웹 상호작용을 위해 추가 구성이 필요할 수 있습니다
모바일용 webview_flutter에 의존하며, 자체 제약 조건이 있음
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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