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()); @override Stream mapEventToState(HelpEvent event) async* { if (event is GetHelpCategoryEvent) { yield* _mapGetHelpCategoryToState(event); } else if (event is GetHelpArticleEvent) { yield* _mapGetHelpArticleState(event); } } Stream _mapGetHelpCategoryToState( GetHelpCategoryEvent event) async* { yield HelpLoading(); try { final List categoryList = await helpRepository.getHelpCategories(event.uid); yield HelpCategoryState(categoryList); } catch (error) { print(error); yield HelpLoadError(); } } Stream _mapGetHelpArticleState(GetHelpArticleEvent event) async* { yield HelpLoading(); try { final List categoryList = await helpRepository.getCategoryArticles(event.categoryId); yield HelpArticleState(categoryList); } catch (error) { print(error); yield HelpLoadError(); } } }