On the home page of the app, we already have an IconButton that the user can press to add a book to their favorites. We only need to connect it to the addFavorites() method in the BooksHelper class to make it work. Let's look at the steps to do that here:
- Get to the ui.dart file, and in the BooksTable class in the build() method, in the last TableCell, edit the IconButton so that in the onPressed() method, it can add (or remove) a book in the favorites list, as follows:
child: IconButton( color: (isFavorite) ? Colors.red : Colors.amber, tooltip: (isFavorite) ? 'Remove from favorites' : 'Add to favorites', icon: Icon(Icons.star), onPressed: () { if (isFavorite) { helper.removeFromFavorites(book, context); ...