Created
July 2, 2020 21:56
-
-
Save irvine5k/ce64a8f74aa1a03881470cfc4c9e9900 to your computer and use it in GitHub Desktop.
Movies Cubit
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
| import 'package:cubit/cubit.dart'; | |
| import 'package:movie_app/src/movies/movie_repository.dart'; | |
| import 'package:movie_app/src/movies/movie_state.dart'; | |
| class MoviesCubit extends Cubit<MoviesState> { | |
| MoviesCubit({this.repository}) : super(InitialState()) { | |
| _getTrendingMovies(); | |
| } | |
| final MovieRepository repository; | |
| void _getTrendingMovies() async { | |
| try { | |
| emit(LoadingState()); | |
| final movies = await repository.getMovies(); | |
| emit(LoadedState(movies)); | |
| } catch (e) { | |
| emit(ErrorState()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment