The problem we have in the RWCourses app at the moment is due to having state that needs to be shared between the CoursesPage and the FilterPage. That state represents the current filter value the user has selected on the FilterPage. You need that state to be communicated to the CoursesPage so that it can filter the course list without requiring the user to restart the app.
You need a mechanism to share the filter state between the different widgets and screens of the app.
Within the Flutter ecosystem, there are a number of tools available to manage the state of your app. These include StatefulWidgets, InheritedWidgets, the Provider package, Scoped Model, the Redux pattern, and the BLoC pattern. In this course you’re going to look at the most basic approach to sharing state, using an InheritedWidget. We have a more advanced course available on the Provider package, and we’ll add other courses covering the other state management approaches in the future.
Using an InheritedWidget lets you lift state up in the widget tree. You move state to the common ancestor of widgets that need to know that state. In the case of the RWCourses app, you need the filter state to be above both the CoursesPage widget and the FilterPage widget.
You don’t want to move the state any higher than that common ancestor, since it’s possible that different parts of your widget tree will need to know completely different state. In the case of this sample app, you’ll need to share state across both screens, so we’ll move state up above the MaterialApp object.