0

we force https on our backend server, after it images used by cached_network_image returns errors:

Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:393)) 

My code (works ok before force https):

CachedNetworkImage(
          imageUrl: addr,
          progressIndicatorBuilder: (context, url, downloadProgress) =>
              CircularProgressIndicator.adaptive(
                  value: downloadProgress.progress),
          errorWidget: (context, url, error) => const Icon(Icons.error),
          httpHeaders: RuntimeMetadata.getTokenAsWholeMap());
sosnus
  • 968
  • 10
  • 28

1 Answers1

4

In your main.dart file, add or import the following class:

class MyHttpOverrides extends HttpOverrides{
      @override
      HttpClient createHttpClient(SecurityContext? context){
        return super.createHttpClient(context)
          ..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
      }
    }

then call this in main()

HttpOverrides.global = MyHttpOverrides();
Hassan
  • 63
  • 5