1

E/flutter (13503): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Cannot open file, path = 'lib/certs/ca.pem' (OS Error: No such file or directory, errno = 2)

   SecurityContext clientContext = new SecurityContext()
     ..setTrustedCertificates('assets/certs/ca.pem');
   var client = new HttpClient(context: clientContext);

   var request = await client.getUrl(
       Uri.parse('192.168.0.132', 10000));
   var response = await request.close();
  assets:
     - assets/
     - assets/certs/

all the files are inside lib folder and inside that lib folder there is certs folder and inside the certs folder all the pem and certificates are there and i need to use it for encryption. it cannot find it but in the actual main function in flutter. if i read file from a different dart code file then it is working but i want that in my project.enter image description here

Arnab
  • 11
  • 2
  • 6
  • In Flutter, you need to put your certificate in assets and load it from there. Be sure to include it in your pubspec.yaml, too. – Richard Heap Oct 18 '19 at 10:32
  • assets: - assets/ - lib/certs/ca.pem yes i have put that but its still the same – Arnab Oct 18 '19 at 11:47
  • Please update the question showing your updated pubspec.yaml and the code where you load the asset using, for example, RootBundle. See https://flutter.dev/docs/development/ui/assets-and-images – Richard Heap Oct 18 '19 at 12:15
  • Possible duplicate of [Flutter add self signed certificate from asset folder](https://stackoverflow.com/questions/54104685/flutter-add-self-signed-certificate-from-asset-folder) – Richard Heap Oct 18 '19 at 12:17
  • yes i did, you can check! issue still there – Arnab Oct 18 '19 at 12:32
  • Simply changing `lib` to `assets` is not going to work. You need to load the asset using `RootBundle` - see the duplicate question – Richard Heap Oct 18 '19 at 13:06
  • Try - assets/certs/* – hoangquyy Oct 25 '19 at 02:53

1 Answers1

0

Move your certs folder from lib folder to asset folder which locate in the your app root directory. If you do not have an asset folder create one in root directory.

Lakmal Fernando
  • 1,420
  • 6
  • 14