Great question! You're comparing two different implementations of a Dart function that returns a Stream<List<TransactionsTableData>>>. While both might appear to do similar things on the surface, they are fundamentally different in behavior and usage, especially regarding asynchrony and how Riverpod's ref.read works.
Incorrect use of ref.read(appDatabaseFacadeProvider.future):
This implies that appDatabaseFacadeProvider is an AsyncNotifierProvider, FutureProvider, or AsyncProvider.
But you’re trying to use it in a sync ref.read() inside an async generator which won’t work as intended.
In fact, ref.read(provider.future) only makes sense inside an async context where you're awaiting a future — not inside a Stream generator like async*.
Mixing paradigms incorrectly:
async* is used to produce a Streamlazily over time, typically from asynchronous computations.
But ref.read(...).getTransactions() is already a Stream. There’s no need to wrap it in an async* unless you're transforming it.
Deadlock / Runtime error risk:
If appDatabaseFacadeProvider is a normal Provider, accessing .future will throw an error.
If used inside a StateNotifier, Widget, or other places where ref.read is not allowed asynchronously, this can cause issues.
✅ Correct Equivalent of the Second Snippet (if needed):
If your intention is to asynchronously access a provider and then return its stream, you probably meant something like this:
dart
Stream<List<TransactionsTableData>> getTransactions() {
final appDb = ref.read(appDatabaseFacadeProvider); // NOT .future!
return appDb.getTransactions(); // Already a Stream
}
But if appDatabaseFacadeProvider is truly an AsyncProvider<AppDatabaseFacade>, then you should do:
Or even better, in a Notifier or StateNotifier, you'd watch the provider and expose the stream reactively.
✅ Summary Table
Feature
First Snippet
Second Snippet
Sync / Async
Synchronous
Asynchronous (async*)
Returns
Direct Stream
Yields from Stream
Provider Type Expected
Normal Provider<T>
Assumes .future exists (e.g. FutureProvider)
Use of .future
❌ Incorrect in this context
⚠️ Only valid in specific async contexts
Correctness
✅ Correct for normal providers
❌ Likely incorrect / misleading usage
✅ Final Recommendation:
Use the first snippet, assuming appDatabaseFacadeProvider is a normal Riverpod Provider<AppDatabaseFacade>.
If you're using AsyncProvider, FutureProvider, or NotifierProvider, adapt accordingly — but don't mix ref.read(provider.future) with async* in a Stream function.
If you're unsure what type your provider is, check how it's declared in your Riverpod setup.