Flutter Certificate

Asked

Viewed 30 times

0

I’m having error to query an api, because it is with error in the certificate I wanted to know if anyone has any idea what can be already tried several ways and nothing. inserir a descrição da imagem aqui

  • Welcome to Stack Overflow. Could you edit the question and put this error as text? Including which part of the code makes this connection would also help to get answers more easily.

1 answer

0

I had that problem the other day! I solved it this way:

void main() {
  HttpOverrides.global = new MyHttpOverrides();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      initialRoute: 'home',
      routes: {
        'home': (BuildContext context) => Login(),
      },
    );
  }
}

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.