Ziad Ghanem
Ziad Ghanem

Reputation: 91

Flutter Riverpod provider widget not rebuilding

This is my code:

class MealsNotifier extends Notifier<List<Meal>> {

@override
  List<Meal> build() {
    return userMeals;
  }
  updateList(List<Meal> meals) {
    state = List.from(meals);
  }
}

final mealsProvider = NotifierProvider<MealsNotifier, List<Meal>>(() {
  return MealsNotifier();
});

In Categories class I have:

final meals = ref.watch(mealsProvider);

In EditMeal class I have:

ref.read(mealsProvider.notifier).updateList(userMeals);

My app structure is Categories -> Meals -> MealDetails -> EditMeal

After I'm done editing the meal, I expect all these widgets to rebuild since Categories has the ref.watch method.

Edit:

Migrated to Notifier. Still the same issue.

Using the debugger, state is being updated, but nothing rebuilds.

Upvotes: 0

Views: 276

Answers (1)

Nour Salman
Nour Salman

Reputation: 33

Given the current details, there's no issue in the update mechanism itself.

Check that userMeals argument is updating before passing it.

If Meals is a List of widgets make sure their configuration (params) are enough for Flutter to differentiate between them, otherwise consider using a ValueKey for each one with a suitable value.

Upvotes: 0

Related Questions