skip to Main Content

I have a nested data structure like this:

User
|-List<WorkoutPlan>
    |-List<Workout>
      |-List<Exercise>

    

Each list is saved on a different json file:

-user.json with the list workout plans’ ids
-workoutPlans.json: Each workout plan has a list of workouts’ id
-workouts.json

For each data structure I have a different bloc:

-UserBloc to manage user info
-WorkoutPlanBloc to manage workoutPlans
-WorkoutBloc to manage workouts

So I’ve made a simple app with

  • page for user info
  • Page with the list of workoutplans
  • Page with the list of workouts of the selected plan.

The problem is that in each page I should have pieces of information of other pages.
For example: on user page I need to show last workout used so I should load informations about workout.

Is there anything wrong in my data structure?

2

Answers


  1. If you need to show info about another model you need to load it in your current bloc. You do not need to limit your bloc to only one model, you can load how many models do you want to build the page.

    Sure, if the model has 500 properties but you need just a few of them, fetch only the required properties to avoid filling the memory with unnecessary data.

    Login or Signup to reply.
  2. I’d say there’s nothing wrong with your setup. You have small Blocs, and that’s fine, easier to test. If you’re one on page and you need info from another Bloc, its accessible, assuming your BlocProviders are further up the widget tree.

    If you need something to happen in response to a change in state from another Bloc, can use BlocListener for that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search