Create A Book Manager Class
We have created an app state manager for our application to manage the state of the appo. Now we will create a Book manager to manage the book data we get for our app.
For this navigate to our book_data.dart and scroll down to a TODO which says Create a Book Manager Class that manages the data Let us create a BookManager class which extends the ChangeNotifier. This Book Manager class will help us to manage the data of the books. Create a Private variable name bookItem and assign our allbooks array to this variable. Let us create a list having Book as its type and a getter method to get the list of books for the list. We will be using an unmodifiable list for this.
Let us create a selectedIndex private variable and give it a value of -1. To access this varibale outsode the class we will have to create a normal variable and assign this varibale with the getter method.
We need a function called bookTapped which will help us change the selectedIndex value. This fuction will take a int index parameter and will assign thi index to the selected index and then notify the listeners .
We will also need a function setSelectedBookItem wich takes a String id as a parameter, This function will let us get the index of the book from the Id and can be assigned to the selectedIndex.