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

Next
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.

Transcript: 06. Create a Book Manager Class

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.