asyncRequest method
Future<Map<String, dynamic> >
asyncRequest({
- required Retrofit retrofit,
- Map<
String, String> ? headers, - Map<
String, dynamic> ? params, - OnResponseErrorCall? errorCall,
- OnResponseCompleteCall? completeCall,
Implementation
Future<Map<String, dynamic>> asyncRequest(
{required Retrofit retrofit,
Map<String, String>? headers,
Map<String, dynamic>? params,
OnResponseErrorCall? errorCall,
OnResponseCompleteCall? completeCall}) {
String requestId = Uuid().v4().toString();
if (completeCall != null) {
_requestActMap[requestId] = completeCall;
}
_syncMap[requestId] = Completer<Map<String, dynamic>>();
_requestForMap(
retrofit: retrofit,
requestId: requestId,
headers: headers,
params: params,
responseCall: _InternalResponseCall(requestId, (String requestId, Map<String, dynamic> dataMap) {
var completer = _syncMap[requestId] as Completer<Map<String, dynamic>>;
completer.complete(Future.value(dataMap));
}, (String requestId, String message, Map<String, dynamic> dataMap) {
var completer = _syncMap[requestId] as Completer<Map<String, dynamic>>;
completer.complete(Future.value(dataMap));
if (errorCall != null) {
errorCall(requestId, message, dataMap);
}
}, (String requestId) {
_finishCall(requestId);
if (completeCall != null) {
completeCall(requestId);
}
}),
enableCache: true,
);
var completer = _syncMap[requestId] as Completer<Map<String, dynamic>>;
return completer.future;
}