Flutter Navigator 2.0

Nov 8 2022 · Dart 2.17.3, Flutter 3.0.2, Android Studio 2020.3

Part 2: Deep Dive Into Navigator 2.0

06. Create a Book Manager Class

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 05. Create App State Notifier Functions Next episode: 07. Use the New App State

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

We have created an app state manager for our application. Using it inside our application, we will need a book manager to manage our books. Navigate to book_data and scroll down where you can see TODO. Create a BookManager class that manages the data. Write a BookManager class extending change notifier as follows. Now, this BookManager class will help us to manage all the books. Create a private variable and assign allbooks to that variable as follows. The allbooks that we get is from the top of the (indistinct) that we have created. Now, we have bookItems, Now, we have bookItems which has all the books present inside it. Let us create a list named bookItems, which will be off type books and a getter method to get those books. Here, what we have done is that we have created bookItems. We get the bookItems data, which will return a list We get the bookItems data, which will return a list of unmodifiable bookItems variable of unmodifiable bookItems variable that we have created on top. The unmodifiable list means The unmodifiable list means that the reference won't change of the list. Now, let us create a private selected index variable and give it a value of minus one. These private variables are not accessible for us outside our class. Now, let us create a getter method to get the selected index. Now next, we will have to create a function which will help us to set the index of the book on which we have tapped as the selected index. Create a function called as void bookTapped. Pass an index value, which we will later set as the selected index. Notify the changes to our change notifier. Create one more function named as setSelectedBookItems, which has a parameter of String id. In this function, we've made sure that the element ID is equal to the ID that we have passed. Then, we set the selected index Then, we set the selected index to the index that we get from the element id. This is the BookManager class which will help us to manage our book's data.