From 29229dfbfd98cf9e0fd0f6f4fca2504e67ddd53f Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 12 Oct 2023 16:48:11 +0300 Subject: [PATCH] Fixes for webview --- lib/ui/app/app_webview.dart | 49 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/ui/app/app_webview.dart b/lib/ui/app/app_webview.dart index 2974d6ffc..074b347d0 100644 --- a/lib/ui/app/app_webview.dart +++ b/lib/ui/app/app_webview.dart @@ -17,7 +17,12 @@ class AppWebView extends StatelessWidget { @override Widget build(BuildContext context) { - return kIsWeb ? _WebWebView(html: html) : _MobileWebView(html: html); + return kIsWeb + ? _WebWebView(html: html) + : _MobileWebView( + html: html, + width: MediaQuery.of(context).size.width - 20, + ); } } @@ -38,9 +43,14 @@ class _WebWebView extends StatelessWidget { } class _MobileWebView extends StatefulWidget { - const _MobileWebView({Key? key, this.html}) : super(key: key); + const _MobileWebView({ + Key? key, + required this.html, + required this.width, + }) : super(key: key); final String? html; + final double width; @override _MobileWebViewState createState() => _MobileWebViewState(); @@ -53,35 +63,36 @@ class _MobileWebViewState extends State<_MobileWebView> @override bool get wantKeepAlive => true; + @override + void initState() { + super.initState(); + + _webViewController = WebViewController() + ..setJavaScriptMode(JavaScriptMode.disabled) + ..setBackgroundColor(const Color(0x00000000)); + + if ((widget.html ?? '').isNotEmpty) { + _webViewController.loadHtmlString( + widget.html!.replaceFirst('width="570"', 'width="${widget.width}"')); + } + } + @override void didUpdateWidget(oldWidget) { super.didUpdateWidget(oldWidget); if (widget.html != oldWidget.html) { - _webViewController.loadHtmlString(widget.html!); - - /* - _webViewController.loadUrl(Uri.dataFromString(widget.html!, - mimeType: 'text/html', encoding: Encoding.getByName('utf-8')) - .toString()); - */ + _webViewController.loadHtmlString( + widget.html!.replaceFirst('width="570"', 'width="${widget.width}"')); } } - /* @override Widget build(BuildContext context) { super.build(context); - return WebView( - initialUrl: Uri.dataFromString(widget.html!, - mimeType: 'text/html', encoding: Encoding.getByName('utf-8')) - .toString(), - onWebViewCreated: (WebViewController webViewController) { - _webViewController = webViewController; - }, - javascriptMode: JavascriptMode.disabled, + return WebViewWidget( + controller: _webViewController, ); } - */ }