downloadBytes method

Future<Uint8List?> downloadBytes(
  1. String? idToken,
  2. String endpoint
)

Implementation

Future<Uint8List?> downloadBytes(String? idToken, String endpoint) async {
  try {
    if(idToken == null || idToken.trim() == '') throw 'AccessToken Null';
    final response = await http.get(
      Uri.parse('$apiUrl/$endpoint'),
      headers: { 'Authorization': 'Bearer $idToken', 'Content-Type': 'application/json' },
    );
    if (response.statusCode == 200) {
      return response.bodyBytes;
    } else {
      throw 'Error get $apiUrl/$endpoint: ${response.body.toString()}';
    }
  } catch (error){
    throw error;
  }
}