read method
Read a value from the system keychain.
Implementation
Future<String?> read(String key) async {
if (Platform.isMacOS) {
final result = await Process.run('security', [
'find-generic-password',
'-a',
key,
'-s',
serviceName,
'-w',
], stdoutEncoding: utf8);
if (result.exitCode == 0) {
return (result.stdout as String).trim();
}
return null;
} else if (Platform.isLinux) {
final result = await Process.run('secret-tool', [
'lookup',
'service',
serviceName,
'account',
key,
], stdoutEncoding: utf8);
if (result.exitCode == 0) {
return (result.stdout as String).trim();
}
return null;
}
throw UnsupportedError('SecureStorage is not supported on this platform');
}