Skip to content

Instantly share code, notes, and snippets.

@pawelsa
Created June 26, 2022 17:44
Show Gist options
  • Save pawelsa/6dee5d5c7e5bd0137274a3cc14a263bb to your computer and use it in GitHub Desktop.
Save pawelsa/6dee5d5c7e5bd0137274a3cc14a263bb to your computer and use it in GitHub Desktop.
Before and after change to use Result
// Before
Future<List<ContentDetailData>> getPopularMovies(int page) =>
_movieApi.getPopular(page).then((content) {
if (content is ContentListResponse) {
return _getMovies(content, true);
}
return <ContentDetailData>[];
});
// After
Future<Result> getPopularMovies(int page) =>
_movieApi.getPopular(page).then((content) {
if (content is ContentListResponse) {
return _getMoviesWithResp(content, true);
} else if (content is NoInternetResponse){
return ErrorResult(ErrorCause.noInternet());
}
return ErrorResult(ErrorCause.unknown()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment