Creating a shopping cart application with InheritedWidget
Let's create the same version of our shopping cart application using InheritedWidget
. We will be reusing the code from the previous section, so it is recommended that you create a new Flutter application named cart_inherited_widget.dart
and copy everything from the previous section's app. We'll proceed as follows:
- First, as we did in Chapter 2, The Core Building Blocks of State Management, let's add the boilerplate code needed for the inherited widget state management technique. Create a new file named
inherited_widget_cart.dart
and add the following code to it:import 'package:flutter/material.dart'; import 'item.dart'; // One class MyCartInheritedWidget extends StatefulWidget { final Widget child; const MyCartInheritedWidget({Key? key, required this.child}) : super(key: key); static MyCartInheritedWidgetState of(BuildContext &...