getRequest static method
Implementation
static Future<NetworkResponseData> getRequest({
required String url,
required String apiFailureMessage,
Map<String, String>? customHeaders,
}) async {
final Uri requestUrl = Uri.parse(
url,
);
try {
http.Response response = await http.get(
requestUrl,
headers: customHeaders,
);
Map<String, dynamic> responseMap = _parseResponse(
response: response,
apiFailureMessage: apiFailureMessage,
url: url,
type: 'GET',
);
if (responseMap.isEmpty ||
responseMap['error'].toString().isNotEmpty ||
responseMap['status'] == 'failure') {
return NetworkResponseData(
hasError: true,
error: responseMap['error'],
status: responseMap['status'],
);
}
return NetworkResponseData(
hasError: responseMap['error'].toString().isNotEmpty,
error: responseMap['error'] ?? '',
status: responseMap['status'] ?? '',
speech: responseMap['speech'] ?? '',
data: responseMap['result'] ?? '',
);
} catch (error) {
debugPrint(
error.toString(),
);
return NetworkResponseData(
hasError: true,
error: error.toString(),
);
}
}