Created
July 6, 2019 20:42
-
-
Save xsahil03x/aaf230c62aad90a7994db202a77f277d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MovieModel extends Model { | |
MovieRepository _movieRepository; | |
ApiResponse<List<Movie>> _movieList; | |
ApiResponse<List<Movie>> get movieList => _movieList; | |
MovieModel() { | |
_movieList = ApiResponse(); | |
_movieRepository = MovieRepository(); | |
fetchMovieList(); | |
} | |
fetchMovieList() async { | |
_movieList = ApiResponse.loading('Fetching Popular Movies'); | |
notifyListeners(); | |
try { | |
List<Movie> movies = await _movieRepository.fetchMovieList(); | |
_movieList = ApiResponse.completed(movies); | |
notifyListeners(); | |
} catch (e) { | |
_movieList = ApiResponse.error(e.toString()); | |
notifyListeners(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment