getDepots method

Future<List<Depot>> getDepots ()

Retrieve the list of depots from the database

Implementation

Future<List<Depot>> getDepots() async {
  DatabaseReference depotsRef = FirebaseDatabase.instance.reference().child(
      'Depots');
  await depotsRef.keepSynced(true);

  return depotsRef.once().then((DataSnapshot snapshot) async {
    List<Depot> depots = List<Depot>();
    Map<dynamic, dynamic> values = snapshot.value;
    values.forEach((key, value) {
      depots.add(Depot.fromMap(key, value));
    });
    return depots;
    }).catchError((error) => error);
}