Skip to content

Instantly share code, notes, and snippets.

@AbedElazizShe
Created February 1, 2022 16:39
Show Gist options
  • Save AbedElazizShe/6109fd814a665eb9582f37948d4624ef to your computer and use it in GitHub Desktop.
Save AbedElazizShe/6109fd814a665eb9582f37948d4624ef to your computer and use it in GitHub Desktop.
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