fetchTransactionAsync function
Implementation
Future<ApiBaseResponse<DTransactionResponse>> fetchTransactionAsync(
String accountId, int currentPage, int pageSize, String refererKey) async {
final url = BaseUrl.baseUrl! + api().transaction;
final Map<String, dynamic> body = {
"id": accountId,
"pagination": {
"current_page": currentPage,
"page_size": pageSize,
"total_pages": 0,
"total_items": 0,
"has_next_page": true,
"has_previous_page": true
}
};
final Map<String, String> headers = {
'token': envDemo().token,
'Content-Type': 'application/json',
'X-Referrer-Key': refererKey,
};
try {
final jsonData = await http.post(
Uri.parse(url),
body: jsonEncode(body),
headers: headers,
);
if (jsonData.statusCode == 200) {
final Map<String, dynamic> decodedJson = jsonDecode(jsonData.body);
final response = ApiBaseResponse<DTransactionResponse>.fromJson(
decodedJson,
(dataJson) => DTransactionResponse.fromJson(dataJson),
);
return response;
} else {
throw Exception('Failed to load data from API');
}
} catch (ex) {
throw Exception('Failed to load data from API ${ex.toString()}');
}
}