I’m struggling to work with stream-based functionalities using clean architecture (Uncle bob / Reso coder), as clean architecture provides rules to work with. A normal flow with Future
methods would be getting data from DataSource
-> Repository
-> UseCase
-> Bloc/Cubit
-> Screen
. This works easily with Future
methods and is easy to conceptualize within the framework of clean architecture. However, I’m not finding a proper way to work in the same manner with streams, from getting data to displaying it on the screen, without breaking the clean architecture rules and following the same structure as with Future
methods.
Do we have to follow same flow as we do for Future
method? if yes then here are my doubts regarding working with stream.
- The repository returns
Future<Either>
forFuture
methods, what will
it return for streams? - How will data mapping be done from the
datasource
to the
repository
? - How is error handling managed?
- How are stream
usecases
utilized? - How are streams used in
Cubit
? - How can memory leaks be handled, and how do we dispose of those
streams properly? - And lastly displaying data in UI from the streams ?
If Not, there are any other ways to handle streams within the framework of clean architecture while adhering to its principles? please suggest them.