If you want to scope a ChangeNotifier to some routes using Provider? To do so, the easiest solution is to have one provider per route, such that instead of:
builder: (_) => SomeValue(),
final value = SomeValue();
'/foo': (_) => Provider.value(value: value, child: Foo()),
'/bar': (_) => Provider.value(value: value, child: Bar()),
'/cannot-access-provider': (_) => CannotAccessProvider(),
It is, on the other hand, not possible to have your model “automatically disposed”. provider is not able in such a situation to know that it is safe to dispose of the object.
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.