fluttercommunity / fluttercommunity/flutter_webview_plugin

Negative http error codes from onHttpError.listen when website is unreachable

未关闭
#786 4 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
1.5k
派生
938
PR 合并指标
30 天内没有已合并 PR

描述

Is there a documentation about the negative http error codes from `onHttpError.listen`?
The goal is to lead to a custom error page on timeouts.

I simulated a non responding server by loading `https://www.google.com:81` which will never finish.
In this case, the listener receives http error code -2 on Android, and -1001 on iOS.

Can I rely on those codes to not change?

**Demo code:**
```
Widget build(BuildContext context) {
final plugin = FlutterWebviewPlugin();
plugin.onHttpError.listen((httpError) {
print('error code: ${httpError.code}, url: ${httpError.url}');
if ((Platform.isAndroid && httpError.code == '-2') ||
(Platform.isIOS && httpError.code == '-1001')) {
// navigate to custom error screen
// not sure if error codes are stable/reliable
}
});
plugin.onStateChanged.listen((state) {
print('state changed: type: ${state.type}, url: ${state.url}');
});

return WebviewScaffold(
initialChild: Center(
child: CircularProgressIndicator(),
),
url: 'https://www.google.com:81',
hidden: true,
);
}
```

**Console outputs and behaviour differ depending on the platform:**

Android:
```
state changed: type: WebViewState.startLoad, url: https://www.google.com:81/
error code: -2, url: https://www.google.com:81/
state changed: type: WebViewState.finishLoad, url: https://www.google.com:81/
```

Android finishes with a website telling about the timeout:
Screenshot 2020-07-22 at 18 32 56

iOS:
```
state changed: type: WebViewState.shouldStart, url: https://www.google.com:81/
state changed: type: WebViewState.startLoad, url: https://www.google.com:81/
error code: -1001, url: ?, runtime type: WebViewHttpError
```
iOS never finishes loading and shows the progress indicator forever.

贡献指南

这个仓库没有索引到贡献指南

调研方向

从演示中展示的 onHttpError.listen 行为开始,并比较 Android 和 iOS 针对模拟的无法访问网站的输出。当完成对这些负代码是否稳定、应如何处理平台差异,以及用户对于自定义超时页面可以依赖什么行为的记录后,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, ios
领域
mobile-dev
Issue 类型
文档
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。