title: Flutter add self signed certificate from asset folder
body: <p>My server provides a Self Signed certificate when calling its HTTPS API. I have the certificate file in the <code>asset</code> folder and referenced its path in <code>pubspec.yaml</code> 
  I have tried passing the certificate to <code>SecurityContext</code> and then using that context to create an <code>HttpClient</code>. But the way I'm passing the certificate to <code>SecurityContext</code> is not working. Here is the code:</p>
  
  <pre><code>Future&lt;ByteData&gt; getFileData(String path) async {
      return await rootBundle.load(path);
  }
  
  void initializeHttpClient() async {
      try {
           Future&lt;ByteData&gt; data = getFileData('assets/raw/certificate.crt');
           await data.then((value) {
               var context = SecurityContext.defaultContext;
               context.useCertificateChainBytes(value.buffer.asInt8List());
               client = HttpClient(context: context);
           });
  
      } on Exception catch (exception) {
           print(exception.toString());
      }
  }
  </code></pre>
  
  <p>The <code>SecurityContext</code> has two methods:<br>
  1) <code>useCertificateChain()</code> this accepts a file path. But when I give the path of the file in my asset folder ('assets/raw/certificate.crt'). It says file not found.<br>
  2) <code>useCertificateChainBytes()</code> the above code is using this method. But this also gives me error like (unexpected end of file).<br></p>
  
  <p><strong>Solution as of now</strong></p>
  
  <p>I am bypassing it using <code>client.badCertificateCallback = (X509Certificate cert, String host, int port)=&gt; true;</code>.<br></p>
  
  <p><strong>but I'd like to make it work with certificate</strong></p>