Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0+2

* Add error display on both iOS and Android when failing to load (e.g. due to 'ATS' on iOS or ssl error on Android).

## 0.1.0+1

* Fix null crash when initialUrl is unset on iOS.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package io.flutter.plugins.webviewflutter;

import android.content.Context;
import android.net.http.SslError;
import android.util.Log;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
Expand All @@ -18,6 +22,7 @@ public class FlutterWebView implements PlatformView, MethodCallHandler {
@SuppressWarnings("unchecked")
FlutterWebView(Context context, BinaryMessenger messenger, int id, Map<String, Object> params) {
webView = new WebView(context);
webView.setWebViewClient(new FlutterWebViewClient());
if (params.containsKey("initialUrl")) {
String url = (String) params.get("initialUrl");
webView.loadUrl(url);
Expand Down Expand Up @@ -120,3 +125,11 @@ private void updateJsMode(int mode) {
@Override
public void dispose() {}
}

class FlutterWebViewClient extends WebViewClient {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
Log.e("webview_flutter", error.toString());
}
}
2 changes: 1 addition & 1 deletion packages/webview_flutter/ios/Classes/FlutterWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

NS_ASSUME_NONNULL_BEGIN

@interface FLTWebViewController : NSObject <FlutterPlatformView>
@interface FLTWebViewController : NSObject <FlutterPlatformView, WKNavigationDelegate>

- (instancetype)initWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
Expand Down
15 changes: 15 additions & 0 deletions packages/webview_flutter/ios/Classes/FlutterWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ - (instancetype)initWithFrame:(CGRect)frame
if ([super init]) {
_viewId = viewId;
_webView = [[WKWebView alloc] initWithFrame:frame];
_webView.navigationDelegate = self;
NSString* channelName = [NSString stringWithFormat:@"plugins.flutter.io/webview_%lld", viewId];
_channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger];
__weak __typeof__(self) weakSelf = self;
Expand Down Expand Up @@ -150,4 +151,18 @@ - (bool)loadUrl:(NSString*)url {
return true;
}

#pragma mark -
#pragma mark WKNavigationDelegate
- (void)webView:(WKWebView*)webView
didFailNavigation:(WKNavigation*)navigation
withError:(NSError*)error {
NSLog(@"%@", error.description);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest that we allow the Flutter application to register error listeners and invoke these, giving the app developer the power to decide whether to print error messages or to do something else with them.

}

- (void)webView:(WKWebView*)webView
didFailProvisionalNavigation:(WKNavigation*)navigation
withError:(NSError*)error {
NSLog(@"%@", error.description);
}

@end
2 changes: 1 addition & 1 deletion packages/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: webview_flutter
description: A Flutter plugin that provides a WebView widget on Android and iOS.
version: 0.1.0+1
version: 0.1.0+2
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter

Expand Down