Created
June 26, 2022 17:44
-
-
Save pawelsa/6dee5d5c7e5bd0137274a3cc14a263bb to your computer and use it in GitHub Desktop.
Before and after change to use Result
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
// 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