generateApiCallCode function
Implementation
void generateApiCallCode(
String apiMethod, String apiEndPoint, String apiName) async {
try {
late String method;
if (apiMethod == 'get-api-call') {
method = "GET";
}
if (apiMethod == 'post-api-call') {
method = "POST";
}
if (apiMethod == 'multipart-api-call') {
method = "MULTIPART";
}
// print("generateApiCallCode ==> $method $apiEndPoint $apiName");
stdout.write('Enter feature name:');
String featureChoice = stdin.readLineSync()!.toLowerCase();
String requestModelName = "";
stdout.write('Do you want to create a model class for api request? (Y/N):');
String requestModelChoice = stdin.readLineSync()!.toLowerCase();
if (requestModelChoice == 'y') {
requestModelName = apiName + "_request_model";
print("modelName ==> $requestModelName");
stdout.write('Enter request model json file path:');
String requestModelJsonFilePath = stdin.readLineSync()!;
createFolder('lib/features/$featureChoice/data/model');
generateDartModel(
requestModelName, featureChoice, requestModelJsonFilePath);
}
stdout
.write('Do you want to create a model class for api response? (Y/N):');
String responseModelChoice = stdin.readLineSync()!.toLowerCase();
String responseModelName = "";
if (responseModelChoice == 'y') {
String modelName = "${apiName}_response_model";
responseModelName = modelName;
print("modelName ==> $modelName");
stdout.write('Enter response model json file path:');
String responseModelJsonFilePath = stdin.readLineSync()!;
///Copy response json to asstes/mock
if (!doesFileExist("assets/mock_json/$apiName.json")) {
String mockJsonFileData =
File(responseModelJsonFilePath).readAsStringSync();
File mockJsonFile =
await File("assets/mock_json/$apiName.json").create();
mockJsonFile.writeAsStringSync(mockJsonFileData);
}
createFolder('lib/features/$featureChoice/data/model');
generateDartModel(modelName, featureChoice, responseModelJsonFilePath);
}
stdout.write('Do you want to add shimmer to this API call? (Y/N):');
String shimmerChoice = stdin.readLineSync()!.toLowerCase();
print("shimmerChoice: " + shimmerChoice);
addAPICall(method.toLowerCase(), apiEndPoint, apiName, featureChoice,
responseModelName, shimmerChoice, requestModelName);
} catch (e) {
print('Error: $e');
exit(1);
}
}