balance method Null safety

Future<double> balance(
  1. {required String token}
)

Checks the user's balance

Implementation

Future<double> balance({required String token}) async {
  final uri = Uri.https(authority, '/wallets/self');
  _dio.options.headers = {'Authorization': 'Bearer $token'};

  late Response<Map<String, dynamic>> res;
  var data = {};
  try {
    res = await _dio.getUri(uri);
    data = res.data as Map<String, dynamic>;
  } on DioError catch (e, s) {
    throw PindoError(
      message: (e.response?.data as Map)['message'],
      statusCode: (e.response?.data as Map)['status'] ?? res.statusCode,
      type: e.type.valueToString,
      stackTrace: s,
    );
  } on TypeError {
    throw PindoCastingError();
  } on Exception {
    // If the exception is none of the two above, just rethrow it
    rethrow;
  }

  if (data.containsKey('amount')) {
    return data['amount'];
  }
  throw PindoUnexpectedResponseError(expected: 'amount', received: data);
}