fluttercommunity / fluttercommunity/flutter_webview_plugin
Negative http error codes from onHttpError.listen when website is unreachable
- 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ả
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:

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.
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
Hướng nghiên cứu
Bắt đầu với hành vi của onHttpError.listen được thể hiện trong bản demo và so sánh đầu ra của Android và iOS đối với trang web không thể truy cập được mô phỏng. Công việc được xem là hoàn tất khi đã ghi lại liệu các mã âm này có ổn định hay không, nên xử lý khác biệt giữa các nền tảng như thế nào và người dùng có thể dựa vào hành vi nào đối với các trang timeout tùy chỉnh.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- android, ios
- Lĩnh vực
- mobile-dev
- Loại issue
- Tài liệu
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100