fluttercommunity / fluttercommunity/flutter_webview_plugin

Bad performance of WebviewScaffold

Ouverte
#386 0 commentaires 7 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
1.5k
Forks
938
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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!

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
dart, flutter
Domaine
mobile
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.