Hay,
as a replacement for Xamarin I tried to create a app with the same functions in flutter. But the webview plugin/package doens't work with the self signed ssl certificate. In Xamarin there was a way to handle the ssl errors and still get the website loaded.
Current code:
@override
void initState() {
super.initState();
final flutterWebviewPlugin = new FlutterWebviewPlugin();
flutterWebviewPlugin.onHttpError.skip(1000);
flutterWebviewPlugin.launch("https url to website", hidden: true,
allowFileURLs: true,
appCacheEnabled: true,
withJavascript: true,
withLocalStorage: true,
withZoom: true);
flutterWebviewPlugin.onHttpError.skip(1000);
flutterWebviewPlugin.onStateChanged((state) async)
{
flutterWebviewPlugin.evalJavascript(
"document.getElementById(\"name\").innerText = \"username\"");
flutterWebviewPlugin.evalJavascript(
"document.getElementById(\"password\").innerText = \"pw\"");
flutterWebviewPlugin.evalJavascript(
"document.getElementById(\"loginbutton\").invokeMember(\"click\")");
var test = flutterWebviewPlugin.evalJavascript(
"document.getElementById(\"errorbox\").innerText");
};
flutterWebviewPlugin.dispose();
flutterWebviewPlugin.close();
Error:
Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Is there a better way then writing an own package or an custom webview in java and swift?
On Android you could modify the plugin. Clone a copy to your local machine and add an additional override to
flutter_webview_plugin/android/src/main/java/com/flutter_webview_plugin/BrowserClient.java
Override
public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error)
with an implementation that simply doeshandler.proceed()
Let's say your project is in
/projects/myproject
and you cloned the plugin into/projects/flutter_webview_plugin
. Make the change in/projects/flutter_webview_plugin/android/src/.../BrowserClient.java
. Then update thepubspec.yaml
of your project with (replaces the existing entry for flutter_webview_plugin):