createTransaction function

Future<Transactions> createTransaction(
  1. int amount,
  2. String username,
  3. String date,
  4. String reason,
  5. String vendor,
)

Implementation

Future<Transactions> createTransaction(int amount, String username, String date,
    String reason, String vendor) async {
  HttpOverrides.global = new MyHttpOverrides();
  final response = await http.post(
    Uri.parse('https://192.168.1.106:45455/api/TransactionsModels'),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(<String, String>{
      'amount': amount.toString(),
      'username': username,
      'date': date,
      'reason': reason,
      'vendor': vendor
    }),
  );

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