hot fix crash app on android when loading webview
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@@ -43,6 +44,7 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
|
|||||||
late double actualHeight;
|
late double actualHeight;
|
||||||
double minHeight = 100;
|
double minHeight = 100;
|
||||||
double minWidth = 300;
|
double minWidth = 300;
|
||||||
|
final double maxHeightForAndroid = 6000;
|
||||||
String? _htmlData;
|
String? _htmlData;
|
||||||
late WebViewController _webViewController;
|
late WebViewController _webViewController;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
@@ -99,18 +101,23 @@ class _HtmlContentViewState extends State<HtmlContentViewer> {
|
|||||||
widget.onCreated?.call(controller);
|
widget.onCreated?.call(controller);
|
||||||
},
|
},
|
||||||
onPageFinished: (url) async {
|
onPageFinished: (url) async {
|
||||||
final scrollHeightText = await _webViewController.runJavascriptReturningResult('document.body.scrollHeight');
|
final scrollHeightText = await _webViewController.runJavascriptReturningResult('document.body.scrollHeight');
|
||||||
final scrollHeight = double.tryParse(scrollHeightText);
|
final scrollHeight = double.tryParse(scrollHeightText);
|
||||||
developer.log('onPageFinished(): scrollHeightText: $scrollHeightText', name: 'HtmlContentViewer');
|
developer.log('onPageFinished(): scrollHeightText: $scrollHeightText', name: 'HtmlContentViewer');
|
||||||
if ((scrollHeight != null) && mounted) {
|
if ((scrollHeight != null) && mounted) {
|
||||||
final scrollHeightWithBuffer = scrollHeight + 30.0;
|
final scrollHeightWithBuffer = scrollHeight + 30.0;
|
||||||
if (scrollHeightWithBuffer > minHeight) {
|
if (scrollHeightWithBuffer > minHeight) {
|
||||||
setState(() {
|
setState(() {
|
||||||
actualHeight = scrollHeightWithBuffer;
|
//TODO: It hotfix for web_view crash on android device and waiting lib web_view update to fix this issue
|
||||||
_isLoading = false;
|
if(Platform.isAndroid && scrollHeightWithBuffer > maxHeightForAndroid){
|
||||||
});
|
actualHeight = maxHeightForAndroid;
|
||||||
|
} else {
|
||||||
|
actualHeight = scrollHeightWithBuffer;
|
||||||
|
}
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (mounted && _isLoading) {
|
if (mounted && _isLoading) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# 8. Unable to save data to indexedDB in onBeforeUnload state of web
|
# 9. Unable to save data to indexedDB in onBeforeUnload state of web
|
||||||
|
|
||||||
Date: 2022-07-11
|
Date: 2022-07-11
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# 10. Crash app when open web_view on android device
|
||||||
|
|
||||||
|
Date: 2022-07-20
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
Open
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
- When using a webview inside of a scrollview,
|
||||||
|
some content renders a completely distorted page and some content even crashes the app.
|
||||||
|
This problem only affects Android the same app, on iOS the same code results in a correclty rendered web page.
|
||||||
|
Rendering the same content also works fine on Android, when not embedding the webview inside of a scrollview.
|
||||||
|
|
||||||
|
- Flutter version has problem: 3.0.3
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
- When using a webview inside of a scrollview,
|
||||||
|
some content renders a completely distorted page and some content even crashes the app.
|
||||||
|
This problem only affects Android the same app, on iOS the same code results in a correclty rendered web page.
|
||||||
|
Rendering the same content also works fine on Android, when not embedding the webview inside of a scrollview.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- From now we waiting web_view lib update and for android device if content of web_view has max height is 6000,
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
- [Issue detail](https://github.com/flutter/flutter/issues/104889)
|
||||||
Reference in New Issue
Block a user