How to solve Flutter CERTIFICATE_VERIFY_FAILED error while performing a POST request?

In order to enable this option globally in your project, here is what you need to do:

  1. In your main.dart file, add or import the following class:
 class MyHttpOverrides extends HttpOverrides{
  HttpClient createHttpClient(SecurityContext? context){
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
  1. In your main function, add the following line after function definition: = MyHttpOverrides();

This comment was very helpful to pass through this matter, and please note that…

This should be used while in development mode, do NOT do this when you want to release to production, the aim of this answer is to
make the development a bit easier for you, for production, you need to fix your certificate issue and use it properly, look at the other answers for this as it might be helpful for your case.

Leave a Comment