fluttercommunity / fluttercommunity/flutter_webview_plugin

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

オープン
#680 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Java
スター
1.5k
フォーク
938
PR マージ指標
30日以内にマージされた PR はありません

説明

## 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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

報告されている Flutter 1.12.13+hotfix.8 と plugin バージョン ^0.3.10+1 を使用して、まず StatefulWidget の initState、_getFile、build、および flutterWebviewPlugin.onUrlChanged listener の動作を再現します。listener と conditional build path がいつ実行されるかを確認します。準備中に loading indicator が表示され、listener が発火して reloaded WebView が表示されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
dart, flutter
領域
mobile
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。