rrousselGit / riverpod

A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
https://riverpod.dev
MIT License
5.82k stars 888 forks source link

ref.refresh() fails when the returned value of a FutureProvider is an empty list #3471

Closed jasonkang14 closed 1 month ago

jasonkang14 commented 1 month ago

Describe the bug A consumer widget fails to watch the change of the returned value of a FutureProvider when the initial value is an empty list

To Reproduce please excuse the sudo code

// this returns an empty list initially
final todoProvider = FutureProvider.autoDispose((ref) async {
  final dio = ref.read(dioProvider);
  final response = await dio.get('/todo');
  final todoList = response.data['data']['todo'] as List<dynamic>;
  return todoList;
});

class TodoWidget extends ConsumerWidget {
   @override
   Widget build(BuildContext context, WidgetRef ref) {
      // todoList updates when the initial `todoList` is not empty, but it does not update when the initial `todoList` is empty
      final todoList = ref.watch(todoProvider);
      return Scaffold(

         IconButton(
            onPressed: () async {
                 await createTodo();
                 ref.refresh(todoProvider);
            }
         )
      )
}

Expected behavior The returned value should be watched and updated

jasonkang14 commented 1 month ago

mybad that was a different error