Maybe someone else has the same issues as I had, so here is how I implemented it, finally. I am showing this for ObjectBox, but some of the methods work for Hive or other databases as well.
My issues was about setting-up the ObjectBox stream and especially about transforming the ObjectBox data model to my domain entities within the stream.
The data streams from the ObjectBox in the data layer, which also contains the repository implementation, through the contracts in the domain layer (I skip use cases here) to the presentation layer, where I am managing the state with flutter-bloc.
The todo domain entity (only showing the id to shorten things):
The data model for ObjectBox including the transformation methods to/from the domain entity
The method
toObjectBox
requires the internal, integer Objectbox id, which I supplement to the method when storing a todo.Now, in the local datasource implementation, I have the following class to stream the todo's.
So the stream is generated and then transformed from the data model
TodoObjectBox
to the domain entityTodo
.In the presentation layer, I instantiate a
TodoListBloc
with the repository and the eventTodoListRequested
to start the stream. The bloc then handles this event with the following routine:I hope this helps someone also trying to stream from Objectbox or another database to the presentation layer using different data models/entities.
Some context to this answer can be found in ResoCoder's TDD tutorial and BlocLibrary's Todo tutorial.