stateParam function

Future<String> stateParam(
  1. String? fp,
  2. String? method,
  3. bool? isApiPath
)

Implementation

Future<String> stateParam(String? fp, String? method, bool? isApiPath) async {
  if (fp == null || method == null) {
    return "()";
  }
  if (isApiPath != null && isApiPath) {
    if (fp.endsWith('.proto')) {
      final responseType = extractProtoMethodResponseType(fp, method);
      if (responseType == 'void' || responseType == 'dynamic') {
        return "()";
      }
      return "($responseType data)";
    }
    try {
      final responseTypeMap = await extractMethodResponseTypeWithField(
        fp,
        method,
        "data,body",
      );
      String responseDataType = responseTypeMap['responseDataType'] ?? "dynamic";
      String result = "($responseDataType data)";
      if (result == "(void data)") {
        result = "()";
      }
      return result;
    } catch (e) {
      print("Error: $e");
    }
    return "()";
  } else {
    // current statePath;
    Map<String, dynamic>? eResult = jsonDecode(
      extractConstructorParams(fp, method),
    );
    // printInfo("currentstateparam eResult $eResult");
    final params = eResult?["data"]?["constructorParams"] ?? "()";
    // printInfo("fp: $fp, method:$method ,\neResult $params");
    return params;
  }
}