Describe the bug
Watching sortedTodosdosProvider using await .future is not showing persisted data. While watching todosProvidereverything works fine
To Reproduce
@riverpod
Future<List<Todo>> sortedTodos(Ref ref) async {
final todos = await ref.watch(todosProvider.future);
return todos..sort((a, b) => a.name.compareTo(b.name));
}
@riverpod
@JsonPersist()
class Todos extends _$Todos {
@override
FutureOr<List<Todo>> build() async {
persist(
ref.watch(riverpodCacheProvider.future),
key: "todos_list",
);
if (Random().nextBool()) {
await Future.delayed(const Duration(seconds: 1), () => throw Exception("Network error"));
}
return Future.delayed(const Duration(seconds: 3), () {
return <Todo>[
const Todo(id: 1, name: "Wash car"),
const Todo(id: 2, name: "Cook"),
];
});
}
}
What works if we remove await .future:
@riverpod
Future<List<Todo>> sortedTodos(Ref ref) async {
final todos = ref.watch(todosProvider).value ?? [];
return todos..sort((a, b) => a.name.compareTo(b.name));
}
Expected behavior
Should show persisted data if parent has data.
Describe the bug
Watching
sortedTodosdosProviderusingawait .futureis not showing persisted data. While watchingtodosProvidereverything works fineTo Reproduce
What works if we remove
await .future:Expected behavior
Should show persisted data if parent has data.