updateBalance function

Future<Balance> updateBalance(
  1. int? balanceId,
  2. int? balance,
  3. String vendor
)

Implementation

Future<Balance> updateBalance(
    int? balanceId, int? balance, String vendor) async {
  HttpOverrides.global = new MyHttpOverrides();
  final response = await http.put(
    Uri.parse('https://192.168.1.106:45455/api/BalanceModels/$balanceId'),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(<String, String>{
      'balanceId': balanceId.toString(),
      'balance': balance.toString(),
      'vendor': vendor
    }),
  );

  if (response.statusCode == 201) {
    // If the server did return a 201 CREATED response,
    // then parse the JSON.
    return Balance.fromJson(jsonDecode(response.body));
  } else {
    // If the server did not return a 201 CREATED response,
    // then throw an exception.
    throw Exception('Failed to update Balance.');
  }
}