Search code examples
flutterdartblocstate-management

Should we separate bloc for many functionality?


hello i want to ask what's better to structured bloc, in my case i have screen to show all jobs, favorite the job and the other screen can create job. Should i create only one bloc or separate bloc for create job, show the job, see job details. I haven't create the bloc since im stil thinking where to put the bloc and how the bloc looks like

enter image description here


Solution

  • See whether to use a single or multiple BLoCs depends on the complexity and relationships between the features.

    If your features (showing all jobs, favoriting jobs, and creating jobs) are closely related and share a significant amount of logic, a single BLoC might make sense for simplicity. However, if each feature has distinct logic, consider separate BLoCs for better maintainability and organization.

    Here's my suggestion:

    1. Home Screen BLoC: Manages the logic for fetching and displaying all jobs.

    2. Favorite Screen BLoC: Handles logic related to favoriting and unfavorite jobs.

    3. Create Job BLoC: Manages the logic for creating new jobs.

    This way, each BLoC is focused on its specific functionality, promoting a cleaner and more modular codebase. It also makes it easier to test and maintain the code as your application grows.