updateBill method Null safety

Future<ApiResponse<String>> updateBill(
  1. Bill bill
)

Update an existing bill at WeBirr Servers, if the bill is not paid yet. The billReference has to be the same as the original bill created. Check if(ApiResponse.error == null) to see if there are errors. ApiResponse.res will have the value of "OK" on success.

Implementation

Future<ApiResponse<String>> updateBill(Bill bill) async {
  var client = RetryClient(http.Client());
  try {
    var resp = await client.put(
        Uri.parse('${_baseAddress}/einvoice/api/postbill?api_key=${_apiKey}'),
        headers: {"Content-Type": "application/json"},
        body: jsonEncode(bill.toJson()));

    if (resp.statusCode == 200) {
      var map = jsonDecode(resp.body) as Map<String, dynamic>;
      return ApiResponse<String>(
          error: map['error'], errorCode: map['errorCode'], res: map['res']);
    } else {
      return new ApiResponse<String>(
          error: 'http error ${resp.statusCode} ${resp.reasonPhrase}');
    }
  } finally {
    client.close();
  }
}