AndroidNavigationDelegate constructor
AndroidNavigationDelegate(
- PlatformNavigationDelegateCreationParams params
Creates a new AndroidNavigationDelegate.
Implementation
AndroidNavigationDelegate(PlatformNavigationDelegateCreationParams params)
: super.implementation(params is AndroidNavigationDelegateCreationParams
? params
: AndroidNavigationDelegateCreationParams
.fromPlatformNavigationDelegateCreationParams(params)) {
final WeakReference<AndroidNavigationDelegate> weakThis =
WeakReference<AndroidNavigationDelegate>(this);
_webViewClient = (this.params as AndroidNavigationDelegateCreationParams)
.androidWebViewProxy
.newWebViewClient(
onPageFinished: (_, android_webview.WebView webView, String url) {
final PageEventCallback? callback = weakThis.target?._onPageFinished;
if (callback != null) {
callback(url);
}
},
onPageStarted: (_, android_webview.WebView webView, String url) {
final PageEventCallback? callback = weakThis.target?._onPageStarted;
if (callback != null) {
callback(url);
}
},
onReceivedHttpError: (
_,
android_webview.WebView webView,
android_webview.WebResourceRequest request,
android_webview.WebResourceResponse response,
) {
if (weakThis.target?._onHttpError != null) {
weakThis.target!._onHttpError!(
HttpResponseError(
request: WebResourceRequest(
uri: Uri.parse(request.url),
),
response: WebResourceResponse(
uri: null,
statusCode: response.statusCode,
),
),
);
}
},
onReceivedRequestError: (
_,
android_webview.WebView webView,
android_webview.WebResourceRequest request,
android_webview.WebResourceError error,
) {
final WebResourceErrorCallback? callback =
weakThis.target?._onWebResourceError;
if (callback != null) {
callback(AndroidWebResourceError._(
errorCode: error.errorCode,
description: error.description,
url: request.url,
isForMainFrame: request.isForMainFrame,
));
}
},
onReceivedRequestErrorCompat: (
_,
android_webview.WebView webView,
android_webview.WebResourceRequest request,
android_webview.WebResourceErrorCompat error,
) {
final WebResourceErrorCallback? callback =
weakThis.target?._onWebResourceError;
if (callback != null) {
callback(AndroidWebResourceError._(
errorCode: error.errorCode,
description: error.description,
url: request.url,
isForMainFrame: request.isForMainFrame,
));
}
},
onReceivedError: (
_,
android_webview.WebView webView,
int errorCode,
String description,
String failingUrl,
) {
final WebResourceErrorCallback? callback =
weakThis.target?._onWebResourceError;
if (callback != null) {
callback(AndroidWebResourceError._(
errorCode: errorCode,
description: description,
url: failingUrl,
isForMainFrame: true,
));
}
},
requestLoading: (
_,
android_webview.WebView webView,
android_webview.WebResourceRequest request,
) {
weakThis.target?._handleNavigation(
request.url,
headers: request.requestHeaders?.map<String, String>(
(String? key, String? value) {
return MapEntry<String, String>(key!, value!);
},
) ??
<String, String>{},
isForMainFrame: request.isForMainFrame,
);
},
urlLoading: (_, android_webview.WebView webView, String url) {
weakThis.target?._handleNavigation(url, isForMainFrame: true);
},
doUpdateVisitedHistory: (
_,
android_webview.WebView webView,
String url,
bool isReload,
) {
final UrlChangeCallback? callback = weakThis.target?._onUrlChange;
if (callback != null) {
callback(AndroidUrlChange(url: url, isReload: isReload));
}
},
onReceivedHttpAuthRequest: (
_,
android_webview.WebView webView,
android_webview.HttpAuthHandler httpAuthHandler,
String host,
String realm,
) {
final void Function(HttpAuthRequest)? callback =
weakThis.target?._onHttpAuthRequest;
if (callback != null) {
callback(
HttpAuthRequest(
onProceed: (WebViewCredential credential) {
httpAuthHandler.proceed(credential.user, credential.password);
},
onCancel: () {
httpAuthHandler.cancel();
},
host: host,
realm: realm,
),
);
} else {
httpAuthHandler.cancel();
}
},
);
_downloadListener = (this.params as AndroidNavigationDelegateCreationParams)
.androidWebViewProxy
.newDownloadListener(
onDownloadStart: (
_,
String url,
String userAgent,
String contentDisposition,
String mimetype,
int contentLength,
) {
if (weakThis.target != null) {
weakThis.target?._handleNavigation(url, isForMainFrame: true);
}
},
);
}