0

In my Flutter app I am using two providers to manage a list display...

  • a 'goalListFutureProvider ' Future provider that retrieves the list of entries to display
  • a 'goalCrudProvider' StateNotifier provider that handles add/edit/delete actions on entries in the list

The code for the list provider is shown below, where state changes in the CRUD provider will trigger a refresh of the future list provider

final goalListFutureProvider = FutureProvider<List<GdGoal>>((ref) {
  ref.watch(goalSchedulingProvider);
  ref.watch(goalCrudProvider);
  final aSearch = ref.watch(goalListSearchProvider);
  return ref.watch(goalServiceProvider).find(aSearch);
});

Within my CRUD provider I am calling a state change as part of the process logic, the 'update' code is shown below..

class GdGoalNotifier extends StateNotifier<bool> {

  Future<bool> update(GdGoal aGoal) async {
    final aRes = await _goalService.update(aGoal);
    state = !state;
    return aRes;
  }

Within the 'update' method is it correct to call 'state = !state' before the end of the function call? Or should I break out this state refresh to a separate CRUD provider method?

user2868835
  • 1,250
  • 3
  • 19
  • 33

0 Answers0