CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate

If you are using flutter with REST APIs, you may come across “CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate” issue.

Cause:

The issue happens mostly when you are trying to access an API and a error caused due to misconfiguration while sending all the root and intermediate certificates to the webserver correctly at the time of communication between the client and the server.

Solution:

The solution to this problem is “HttpOverrides“. Lets see how to solve the flutter issue –

Add below class in your main.dart file

Add add below line in your main() method-

With the above changes you may additionally come across below compilation error –

Error: The parameter ‘context’ of the method ‘MyHttpOverrides.createHttpClient’ has type ‘SecurityContext’, which does not match the corresponding type, ‘SecurityContext?’, in the overridden method, ‘HttpOverrides.createHttpClient’. ‘SecurityContext’ is from ‘dart:io’.

to remove above compilation error –

make note of the “?” symbol along with SecurityContext. It will solve your compilation error.

Try to reload your application and check, the API will go through successfully without If you are using flutter with REST APIs, you may come across “CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate” error.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.