Creating a separate controller allows for better separation of concerns in your code. By having a dedicated controller class, you can encapsulate the logic related to handling specific functionalities or operations, such as form submissions or API calls. This helps in keeping your notifier classes focused on managing state while delegating the business logic to the controller.
Additionally, using a controller class enables better code organization and reusability. It allows you to centralize common operations that might be needed across multiple widgets or screens, promoting a more modular and maintainable codebase. This approach aligns with best practices in software development, where each component has a clear responsibility, leading to cleaner and more scalable code.
In the context of Flutter and state management with Riverpod, utilizing controllers can enhance the overall structure of your app and improve its maintainability in the long run. While it may seem like an extra step initially, the benefits of having separate controllers become more apparent as your app grows in complexity and functionality.
Passing context or ref object is not best practices but they are one of the common practices. Remember we are doing MVC architecture, So it’s extremely difficult to read api data from the server, without passing a ref or context object. But this is all about MVC architecture, we may clean architecture as well, but clean architecture introduces a lot of extra code. So it depends on your architecture.
With clean architecture you don’t need to pass ref or context, but it comes with a lot of extra code.
MVC is easy to follow follow but make your context or ref tightly coupled.