'How to create multiple instance of same provider in flutter

I'm using a provider to fetch the data and notify the listeners as follows:

class CategoryProvider with ChangeNotifier {

  Future<void> getData() async {
     ......
     ......
     notifyListeners();
   }

}

My CategoryListView widget is listening to this provider as follows:

Widget build(BuildContext context) {
    var collectionData = Provider.of<CategoryProvider>(context);
}

I'm pushing new instance of CategoryListView as follows:

Navigator.of(context).pushNamed(CategoryListView.routeName);

I'm pushing new instances of CategoryListView from CategoryListView widget itself. It works fine on pushing new instances, but on navigating back, all the CategoryListView widgets are showing the data of the latest CategoryListView widget pushed into the stack as it's listening to the same provider. How can I create new instance of provider and associate it to a widget instance? Is there a better approach to handle this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source