getNewsAndEvents method

Future<List<NewsAndEventsItem>> getNewsAndEvents ()

Retrieve the news and events items from the database

Implementation

Future<List<NewsAndEventsItem>> getNewsAndEvents() async {
  DatabaseReference newsAndEventsRef = FirebaseDatabase.instance.reference().child(
      'NewsAndEvents');
  await newsAndEventsRef.keepSynced(true);
  List<NewsAndEventsItem> newsAndEventsList = List<NewsAndEventsItem>();

  return newsAndEventsRef.once().then((DataSnapshot snapshot) {
    Map<dynamic, dynamic> items = snapshot.value;
    items.forEach((key, value) {
      newsAndEventsList.add(NewsAndEventsItem.fromMap(value));
    });
    newsAndEventsList.sort((a,b) => a.compareTo(b));
    return newsAndEventsList;
  }).catchError((error) => error);
}