I was recently studying state management (flutter provider), and in every example I saw it was necessary to create a single source of truth so that the data could be read and updated in the application. However, in an authorial application of mine I came across the need to dynamically create several instances of a controller class.
This is the screen I am working on:
Its a carousel builder, that builds a list of widgets with given data, there is many screens in this configuration that can be accessed, so I need multiple instances of a controller;
This is the controller class I created (not complete yet):
class SelectedItemsController {
Map<int, List<int>> itemCods = {};
Map<int, List<bool?>> boolList = {};
SelectedItemsController(this.itemCods , this.boolList);
}
I was trying to do this: Every time I click on an Item, the controller class will update the item cods, and later I will use the data to rebuild this screen for each slider, if needed, but I dont know if I can create multiple instances of the controller for each screen with this configuration. Any suggestion?