fluttercommunity / fluttercommunity/flutter_webview_plugin

listener doesn't fire when build() has conditional statement that return Widgets

Abierto
#680 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
1.5k
Forks
938
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## System info

Issue occurs on: both
Plugin version: ^0.3.10+1
Flutter doctor output:

```
PS C:\Users\Alex\git\webfocus-mobile> flutter doctor -v
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.657], locale en-US)
• Flutter version 1.12.13+hotfix.8 at C:\Users\Alex\apps\flutter
• Framework revision 0b8abb4724 (4 weeks ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced81d
• Dart version 2.7.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\Alex\AppData\Local\Android\Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = C:\Users\Alex\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] IntelliJ IDEA Community Edition (version 2019.3)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.3.1
• Flutter plugin version 44.0.3
• Dart plugin version 193.6494.35

[√] VS Code (version 1.42.1)
• VS Code at C:\Users\Alex\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.8.1

[√] Connected device (1 available)
• Pixel XL • HT75V0200339 • android-arm64 • Android 10 (API 29)

• No issues found!
```

In my flutter app I am loading html files that are received from MethodChannel. Since this operation might take some time I'd like to show CircularProgressIndicator while file is being copied and flutter_webview_plugin is reloaded with received html. The code is below:

```
class _WebViewContainerState extends State with WidgetsBindingObserver {
FlutterWebviewPlugin flutterWebviewPlugin;
bool _isReportLoaded = false;
...
...
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);

_getFile();

flutterWebviewPlugin = FlutterWebviewPlugin();

flutterWebviewPlugin.onUrlChanged.listen((String url) {
setState(() {
_isReportLoaded = true;
});
});
}

_getFile(){
_isReportLoaded = false;

Future _file;

Future.delayed(const Duration(milliseconds: 5000), () {
_file = Utils.getFileFromServer();
flutterWebviewPlugin.reloadUrl('file://${_file.path}');
});
}

@override
Widget build(BuildContext context) {
if (!_isReportLoaded) {
return Scaffold(
body: CircularProgressIndicator(),
);
}
return _buildWebView();
}

Widget _buildWebView() {
return WebviewScaffold(
url: 'about:blank',
withJavascript: true,
withZoom: true,
withLocalStorage: true,
appBar: AppBar(
title: Text(_fileName),
),
);
}
}
```

The issue is with flutterWebviewPlugin.onUrlChanged.listen not get fired when build method has conditional return of Widgets. If I have as

```
Widget build(BuildContext context) {
if (!_isReportLoaded) {
return Scaffold(
body: CircularProgressIndicator(),
);
}
return _buildWebView();
}
```
Then listener doesn't get called. But if I change it to the following, then the listener works fine, _isReportLoaded is set accordingly, but I don't get CircularProgressIndicator() that I am trying to show while data is prepared and WebView is reloaded.
```
Widget build(BuildContext context) {
if (!_isReportLoaded) {
writeLog("Not loaded...");
}
return _buildWebView();
}
```
Am I doing something wrong here? The above code are just extracts from my code just to convey idea of what I am trying to do.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Empieza reproduciendo el comportamiento de initState, _getFile, build y el listener flutterWebviewPlugin.onUrlChanged de StatefulWidget usando la versión reportada de Flutter 1.12.13+hotfix.8 y la versión del plugin ^0.3.10+1. Comprueba cuándo se ejecutan el listener y la ruta de build condicional; la tarea está terminada cuando el indicador de carga aparece durante la preparación y el listener se activa, de modo que se muestra la WebView recargada.

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
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.