close

[Solved] CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate in flutter

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate Error Occurs ?

I am making API call in my app. But I am facing certificates related error. Here is my code:

    try {
      http.post('url',
          body: {
            "email": emailcontroller.text,
            "password": passwordcontroller.text
          }).then((response) {
        print("Reponse status : ${response.statusCode}");
      });
    } catch (e) {
      print(e.toString());
    }

But I am Facing this error.

E/flutter ( 6264): HandshakeException: Handshake error in client (OS Error: E/flutter ( 6264):  CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:363))

How to Solve CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate Error?

  1. How to Solve CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate Error?

    To Solve CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate Error you just need to enable this option globally in your project. Just use the below method and use it in your main.dart

  2. CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate

    To Solve CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate Error you just need to enable this option globally in your project. Just use the below method and use it in your main.dart

Solution 1

This is for http library method. here is what you need to do in order to enable this option globally in your project.

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());
}

Solution 2

If you are using Dio then just do this:

Dio dio = new Dio();
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
    (HttpClient client) {
  client.badCertificateCallback =
      (X509Certificate cert, String host, int port) => true;
  return client;
};

Solution 3

Also Check for

  • Your API is support HTTPS or HTTP and Please If your API is not support HTTPS then just use HTTP.
  • Also Check the device date and time in device settings. The device date and time is set to previous date. And you are trying to call API then you have to face this error

Summery

So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below which solution worked for you. Thank You.

Also Check Out Below Tutorials

Leave a Comment

%d bloggers like this: