fluttercommunity / fluttercommunity/flutter_webview_plugin

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

Đang mở
#680 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
1.5k
Fork
938
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.