1

I'm trying to read the file tls/cert.pem from my flutter client code as below:

final channel = ClientChannel('10.0.2.2',
    port: 9000,
    options: ChannelOptions(
      credentials: ChannelCredentials.secure(
        certificates: new File('tls/cert.pem').readAsBytesSync(),
        authority: 'localhost',
      ),
      codecRegistry:
      CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
    ),
  );

Please note that tls/cert.pem file is already added to the pubspec.yaml asset list:

assets:
    - tls/cert.pem  
    ...

My error messages :

E/flutter (24635): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PathNotFoundException: Cannot open file, path = 'tls/cert.pem' (OS Error: No such file or directory, errno = 2)
E/flutter (24635): #0      _File.throwIfError (dart:io/file_impl.dart:629:7)
E/flutter (24635): #1      _File.openSync (dart:io/file_impl.dart:473:5)
E/flutter (24635): #2      _File.readAsBytesSync (dart:io/file_impl.dart:533:18)
...

While I'm getting the error message above, anyone can answer what's wrong with my code and settings?

doublechecked the relative path, file existence, removal from the asset list

BeeKay
  • 21
  • 1
  • 2

0 Answers0