Source
Future<PrivateKey> getKeyFromFile(String path) async { var file = new File(path); PrivateKey key; if (!file.existsSync()) { key = await PrivateKey.generate(); file.createSync(recursive: true); file.writeAsStringSync(key.saveToString()); } else { key = new PrivateKey.loadFromString(file.readAsStringSync()); } return key; }