how to implement WebSocket with clean architecture and bloc library flutter?

Viewed 1646

i'm trying to implement WebSocket in flutter using clean architecture my problem is how to get data from data source cuz in the case of using rest APIs you simply request and await data and get it from the data layer but in real-time apps such as using web socket how do I return data continuously without requesting, in which layer should I put WebSocket code, how to get data and sent it to bloc?

1 Answers

So, websockets need to know when they are initialized, if you dont want to make a request directly to connect a socket, you can use initState to enable connection.

For clean porpouse, on data layer , domain , infra , you dont expect Future methods, change "Future" to "Stream", and listen to them.

  • Do not forget to call "your_stream".close() inside dispose method.
Related