I have started working with flutter and dart a few days ago and it's going well so far. Really nice tool, but for the app, I'm building I need a picture from a webserver a whenever I'm trying to call it with new Image.network(URL)
this exception is thrown:
HandshakeException:
Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(ssl_cert.c:345)).
Thanks in advance if anyone could help me.
A way to skip the problem of SSL certification and solve the Image.network(url)
issue is to use the following code:
import 'dart:io';
class MyHttpOverrides extends HttpOverrides{
@override
HttpClient createHttpClient(SecurityContext context){
return super.createHttpClient(context)
..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
}
}
void main(){
HttpOverrides.global = new MyHttpOverrides();
runApp(new MyApp());
}
I got same issue ! Able to solve it app (It's a server related problem, so Better solve it on server side! ) sol: Add user trust certificate locally ! or skip checking ! I choose to add certificate. Add your certificate(for your specific domain) as an asset in your pubsec.yaml file. (You can collect it form web browser)
assets:
- assets/raw/certificate.pem
Then add the following code somewhere in your application before making network requests. For example, in the main function.
void main() async{
await WidgetsFlutterBinding.ensureInitialized();
ByteData data = await
rootBundle.load('assets/raw/certificate.pem');
SecurityContext context = SecurityContext.defaultContext;
context.setTrustedCertificatesBytes(data.buffer.asUint8List());
runApp(MyApp());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With