Error when ChangeNotifierProvider and MaterialPageRoute used together

Solution 1:

It is because you are using child in provider, which means the widget won't build upon the provider.

You should use builder:

ChangeNotifierProvider<A>.value(
  value: a,
  builder: (context, child) => const NewPage(),
);

Now the provider are able to inject the dependency(A), and rebuild your desired widget(NewPage) with the correct context.