'badCertificateCallback function of HttpClient get the wrong type

i am trying to fix CERTIFICATE_VERIFY_FAILED (in development mode), it seems this answer is good https://stackoverflow.com/a/61312927/8010101, so i tried it, but this error show up

A value of type 'bool Function(X509Certificate, String, int)' can't be assigned to a variable of type 'bool Function(X509Certificate, String, int)?'.

this is my code from main.dart

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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source