fetchTransactions function

Future<List<Transactions>> fetchTransactions()

Implementation

Future<List<Transactions>> fetchTransactions() async {
  HttpOverrides.global = new MyHttpOverrides();
  final response = await http
      .get(Uri.parse('https://192.168.1.106:45455/api/TransactionsModels'));
  List<Transactions> transactions = [];

  if (response.statusCode == 200) {
    // If the server did return a 200 OK response,
    // then parse the JSON.
    var transactionsJson = json.decode(response.body);
    for (var transactionsJson in transactionsJson) {
      transactions.add(Transactions.fromJson(transactionsJson));
    }
    return transactions;
  } else {
    // If the server did not return a 200 OK response,
    // then throw an exception.
    throw Exception('Failed to load Transactions');
  }
}