getArticles method

Future<List<EducationArticle>> getArticles (
  1. String category
)

Retrieve the articles of a particular category from the database

Implementation

Future<List<EducationArticle>> getArticles(String category) async {
  DatabaseReference categoryRef = FirebaseDatabase.instance.reference().child(
      'Articles/$category');
  return categoryRef.once().then((DataSnapshot snapshot) {
    List<EducationArticle> articles = List<EducationArticle>();
    Map<dynamic, dynamic> values = snapshot.value;
    values.forEach((key, value) {
      articles.add(EducationArticle.fromMap(value));
    });
    articles.sort((a,b) => a.compareTo(b));
    return articles;
  }).catchError((error) => error);
}