Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Created July 6, 2019 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xsahil03x/aaf230c62aad90a7994db202a77f277d to your computer and use it in GitHub Desktop.
Save xsahil03x/aaf230c62aad90a7994db202a77f277d to your computer and use it in GitHub Desktop.
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