riverpod:有人知道处理在 StreamProvider 中加载 AsyncValue 的模式吗?

riverpod: Does someone know a pattern for dealing with loading AsyncValue inside an StreamProvider?

问题是如果 aStreamProvider 正在加载,return 应该做什么。 returned 需要是 Stream,但实际上代码需要等待并且在加载 aStreamProvider 之前不发送任何内容(因为它需要 compute_something

final aStreamProvider = StreamProvider((ref) => Stream.empty()); // just an example - imagine something complicated
final bStreamProvider = StreamProvider<int>((ref) {
  final myAsyncValue = ref.watch(aStreamProvider);
  return myAsyncValue.when(data: compute_something,
  loading: what_to_do_here,
  error: (_, __) => throw Exception());
}

感谢

您应该 return AsyncValue.loading(),因为实际上在加载内部流时,您也在加载。