I want to load a NetworkImage
in Flutter but can't get it to work because of a:
Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:393))
Does not work (Image from Google Cloud Storage Cloud CDN)
NetworkImage("https://cdn.vaandra.com/items/f69f662f-41ff-4bb1-bd50-75a70b7ca6a5/439806b1-cacc-4d58-85a5-601bcb825fe3-p-500")
However this does work (test image from the webz)
NetworkImage("https://picsum.photos/250?image=9")
This is the full error message:
======== Exception caught by image resource service ================================================
The following HandshakeException was thrown resolving an image codec:
Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:393))
When the exception was thrown, this was the stack:
#0 _SecureFilterImpl._handshake (dart:io-patch/secure_socket_patch.dart:99:46)
#1 _SecureFilterImpl.handshake (dart:io-patch/secure_socket_patch.dart:142:25)
#2 _RawSecureSocket._secureHandshake (dart:io/secure_socket.dart:911:54)
#3 _RawSecureSocket._tryFilter (dart:io/secure_socket.dart:1040:19)
<asynchronous suspension>
Image provider: NetworkImage("https://cdn.vaandra.com/items/f69f662f-41ff-4bb1-bd50-75a70b7ca6a5/439806b1-cacc-4d58-85a5-601bcb825fe3-p-500", scale: 1.0)
Image key: NetworkImage("https://cdn.vaandra.com/items/f69f662f-41ff-4bb1-bd50-75a70b7ca6a5/439806b1-cacc-4d58-85a5-601bcb825fe3-p-500", scale: 1.0)
====================================================================================================
Although the error claims that this is a certificate problem I can't understand how it does work with that public image that also comes through https
?
CodePudding user response:
Create a class that extends the http override
class MyHttpOverrides extends HttpOverrides{
@override
HttpClient createHttpClient(SecurityContext context){
return super.createHttpClient(context)
..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
}
}
And use it in the main function
void main(){
HttpOverrides.global = new MyHttpOverrides();
runApp(MyApp());
}