fluttercommunity / fluttercommunity/flutter_webview_plugin
Bad performance of WebviewScaffold
- Lenguaje dominante
- Java
- Estrellas
- 1.5k
- Forks
- 938
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I noticed a relatively high CPU consumption when using the WebviewScaffold. It happens even when there are no changes within the WebView. The flutter performance profiler shows that there 60 frames per second updated despite no visible state changes.
After some investigation I've found that the culprit is the default initial child instantiated in webview_scaffold.dart line 148
```dart
child: widget.initialChild ?? const Center(child: const CircularProgressIndicator()),
```
It looks like this animated widget stays running all the time even when it's not visible. A simple workaround was to provide
```dart
initialChild: Container(),
```
in the WebviewScaffold constructor. It definitely fixes the issue with frame updates and high CPU load and subjectively makes the WebView working smoother.
I'm not sure what's the best way of fixing it. Perhaps having an empty initial child by default or removing this child when a page is loaded. But some changes seems to be necessary.
BTW, thanks for the great plugin!
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Read webview_scaffold.dart around line 148 and inspect how the default initialChild is used compared with the explicit Container() workaround. Reproduce the WebviewScaffold case with Flutter's performance profiler, then verify that the unnecessary 60 FPS updates and high CPU consumption no longer occur when the WebView has no visible changes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- dart, flutter
- Área
- mobile
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100