fetchTodos method

Future<void> fetchTodos()

Terminal Action: Affects the whole screen state

Implementation

Future<void> fetchTodos() async {
  state = state.copyWith(status: HomeUIStatus.loading);
  final repository = ref.read(todoRepositoryProvider);
  final result = await repository.getTodos();

  result.fold(
    (failure) => state = state.copyWith(
      status: HomeUIStatus.error,
      errorMessage: failure.toString(),
    ),
    (todos) => ref.read(todosProvider.notifier).setTodos(todos),
  );
}