// import 'dart:async'; import 'package:bytedesk_kefu/blocs/help_bloc/bloc.dart'; import 'package:bytedesk_kefu/model/helpArticle.dart'; import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/repositories/help_repository.dart'; import 'package:bloc/bloc.dart'; class HelpBloc extends Bloc { // final HelpRepository helpRepository = new HelpRepository(); HelpBloc() : super(new UnHelpState()) { on(_mapGetHelpCategoryToState); on(_mapGetHelpArticleState); } // @override // Stream mapEventToState(HelpEvent event) async* { // if (event is GetHelpCategoryEvent) { // yield* _mapGetHelpCategoryToState(event); // } else if (event is GetHelpArticleEvent) { // yield* _mapGetHelpArticleState(event); // } // } void _mapGetHelpCategoryToState( GetHelpCategoryEvent event, Emitter emit) async { emit(HelpLoading()); try { final List categoryList = await helpRepository.getHelpCategories(event.uid); emit(HelpCategoryState(categoryList)); } catch (error) { print(error); emit(HelpLoadError()); } } void _mapGetHelpArticleState( GetHelpArticleEvent event, Emitter emit) async { emit(HelpLoading()); try { final List categoryList = await helpRepository.getCategoryArticles(event.categoryId); emit(HelpArticleState(categoryList)); } catch (error) { print(error); emit(HelpLoadError()); } } }