Created
June 25, 2020 18:09
-
-
Save denisviana/99473a62f8a48dc871052015e4b188a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository { | |
final ApiClient _myApiClient; | |
final ToDoDao _dao; | |
Repository(this._remoteDataSource, this._localDataSource); | |
@override | |
Stream<Resource<List<ToDoItem>>> toDoItemsStream() { | |
return NetworkBoundResources<List<ToDoItem>,List<ToDoItem>>() | |
.asStream( | |
loadFromDb: _dao.allActiveToDoItemsStream, | |
shouldFetch: (data) => data == null || data.isEmpty, | |
createCall: _remoteDataSource.getToDoItemsFromApi(), | |
processResponse: (request) => request.toResult(), | |
saveCallResult: (result) => _dao.insertToDo(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment