Fixes for webview
This commit is contained in:
parent
6e05bb8b92
commit
29229dfbfd
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue