Home > Back-end >  Trying to get recommended books from list unable to build correct logic
Trying to get recommended books from list unable to build correct logic

Time:08-20

Here is method in dart with books as a List need to check based on boolean value if its recomended assign that books to recommended[i] list. Need to make correct logic for it in dart. Please help THank you.

void recommendedBooksLists(RxList<dynamic> books) {
    if (books.recommended==true){
// if books are recommended assign those books something like recommeded.assign(book)
    }

CodePudding user response:

you have to loop through the values of the books and push the book which is recommended as example

void recommendedBooksLists(RxList<dynamic> books) {
    recommended = [];
    for(var book in books.value){
        if(book['recommended'] as bool == true){
            recommended.add(book);
        }
    }
}

CodePudding user response:

List<Book> allBooks;
List<Book> recommendedBooks;

for(int i = 0; i< allBooks.length; i  ) {
  if(allBooks[i].recommend==true) {
    recommendedBooks.add(allBooks[i]);
  }
}
  • Related