Let's add a second screen to the app and lift the State higher in the tree:
- Update the PlanProvider class so that it can handle multiple plans. Change the storage property from a single plan to a list of plans:
final _plans = <Plan>[];
- We also need to update the of-context method so that it returns the correct type. This will temporarily break the project, but we will fix this in the next few steps:
static List<Plan> of(BuildContext context) {
final provider = context.dependOnInheritedWidgetOfExactType
<PlanProvider>();
return provider._plans;
}
- PlanProvider is also going to have a new home in the widget tree. Instead of sitting underneath MaterialApp, we actually want this global state widget to be placed above it. Update the build method in main.dart so that it looks like this:
return PlanProvider(
child: MaterialApp(
theme: ThemeData(primarySwatch: Colors.purple),
- We can now create a new screen to manage...