extractProtoMethodResponseType function

String extractProtoMethodResponseType(
  1. String filePath,
  2. String methodName
)

Implementation

String extractProtoMethodResponseType(String filePath, String methodName) {
  final content = File(filePath).readAsStringSync();
  final services = parseProtoServices(content);

  for (final service in services) {
    for (final method in service.methods) {
      if (method.name == methodName) {
        final responseType = method.responseType;
        if (responseType == 'void' || responseType == 'google.protobuf.Empty') {
          return 'void';
        }
        return method.isServerStreaming
            ? 'Stream<$responseType>'
            : responseType;
      }
    }
  }
  return 'dynamic';
}