class MyHttpOverrides extends HttpOverrides { final String cert;
MyHttpOverrides(this.cert);
@override HttpClient createHttpClient(SecurityContext? context) { final SecurityContext securityContext = SecurityContext(withTrustedRoots: false); securityContext.setTrustedCertificatesBytes(cert.codeUnits); return super.createHttpClient(securityContext) ..badCertificateCallback = (X509Certificate cert, String host, int port) => true; }
I call this in main.dart:
final cert = await rootBundle.loadString('assets/certificates/dev-cert.pem'); HttpOverrides.global = MyHttpOverrides(cert);
I used this method but sometimes it works and sometimes it doesn't. Now it doesn't work anymore. I think maybe the certificate file has changed. please help me