How to consume Provider after navigating to another route? How to consume Provider after navigating to another route? dart dart

How to consume Provider after navigating to another route?


You can pass the existing model forward creating a new ChangeNotifierProvider using the value of the existing one.

For that, you need to use ChangeNotifierProvider.value constructor passing the existing model2 as the value.

If you already have an instance of ChangeNotifier and want to expose it, you should use ChangeNotifierProvider.value instead of the default constructor.

MaterialPageRoute(  builder: (context) => ChangeNotifierProvider<Model2>.value(    value: model2,    child: SecondRoute(),  ),);