flutter services injection in clean architecture

306

You've not mentioned to the layers you've adopted from the clean architecture and the use case you need to consider such a design, so it makes your question opinion based.

A service like audio player is more a UI related thing and it does not contain business logic, as it mentioned in the clean architecture use cases layer contains application specific business rules. You should clarify how your playing file involves business logic. Although you still can use bloc for player state management.

Share:
306
mohammad
Author by

mohammad

Updated on December 27, 2022

Comments

  • mohammad
    mohammad over 1 year

    I am new to clean architecture in flutter,

    I know that we should inject our repositories via usecases into presenters like BLoc but I don't know how to use services like an audio service, for example we should pause, resume, seek and ... from the audioServiceImpl,

    does it need a usecase for each opearation like play or we should inject the service directly into BLoc ?

  • mohammad
    mohammad over 3 years
    the layers I have are: domain (entities, usecases), infrastructure (repositories, services), external (datasources, drivers), presentation (BLoc, UI)
  • mohammad
    mohammad over 3 years
    for now, I have implemented it inside infrastructure, because it needs some persistance for audioPosition and last musics and also last index to remember them, so I think it has some application business logic, is it right ?
  • RaSha
    RaSha over 3 years
    I think you can keep player independent in the presentation layer. In your player bloc, send a request through equivalent use case to fetch the files' play state and then initialize player. When a player event is received in your bloc you can send updated play state to bellow layer in order to persist it.