Created
February 1, 2022 16:39
-
-
Save AbedElazizShe/6109fd814a665eb9582f37948d4624ef to your computer and use it in GitHub Desktop.
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
import 'package:bloc/bloc.dart'; | |
import 'package:domain/domain.dart'; | |
import 'package:flutter_clean_architecture/core/enums.dart'; | |
import 'package:get_it/get_it.dart'; | |
import 'articles_state.dart'; | |
class ArticlesCubit extends Cubit<ArticlesState> { | |
ArticlesCubit() : super(const ArticlesInitialState()); | |
void getArticles({required ContentType type, bool forceUpdate = false}) { | |
emit(const ArticlesLoadingState()); | |
GetIt.instance<GetArticlesUseCase>().call( | |
requestType: _getRequestType(type), | |
forceUpdate: forceUpdate, | |
onSuccess: (List<ArticleModel> articles) { | |
emit(ArticlesLoadedState(articles)); | |
}, | |
onFailure: () {}); | |
} | |
RequestType _getRequestType(ContentType type) { | |
switch (type) { | |
case ContentType.mostEmailed: | |
return RequestType.mostEmailed; | |
case ContentType.mostViewed: | |
return RequestType.mostViewed; | |
case ContentType.mostShared: | |
return RequestType.mostShared; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment