nyApi<T> function
API helper
Implementation
Future<dynamic> nyApi<T>(
{required dynamic Function(T) request,
Map<Type, dynamic> apiDecoders = const {},
BuildContext? context,
Map<String, dynamic> headers = const {},
String? bearerToken,
String? baseUrl}) async {
assert(apiDecoders.containsKey(T),
'Your config/decoders.dart is missing this class ${T.toString()} in apiDecoders.');
dynamic apiService = apiDecoders[T];
if (context != null) {
apiService.setContext(context);
}
// add headers
if (headers.isNotEmpty) {
apiService.setHeaders(headers);
}
// add bearer token
if (bearerToken != null) {
apiService.setBearerToken(bearerToken);
}
// add baseUrl
if (baseUrl != null) {
apiService.setBaseUrl(baseUrl);
}
return await request(apiService);
}