|
|
@ -0,0 +1,41 @@ |
|
|
|
import 'dart:async'; |
|
|
|
import 'package:bloc/bloc.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/core/status/base_status.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/features/question/domain/entity/question_entity.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/features/question/domain/usecases/get_question_usecase.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/features/question/presentation/bloc/question_event.dart'; |
|
|
|
import 'package:hadi_hoda_flutter/features/question/presentation/bloc/question_state.dart'; |
|
|
|
|
|
|
|
class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
|
/// ------------constructor------------ |
|
|
|
QuestionBloc( |
|
|
|
this._getQuestionUseCase, |
|
|
|
) : super(const QuestionState()) { |
|
|
|
on<GetQuestionEvent>(_getQuestionEvent); |
|
|
|
} |
|
|
|
|
|
|
|
/// ------------UseCases------------ |
|
|
|
final GetQuestionUseCase _getQuestionUseCase; |
|
|
|
|
|
|
|
/// ------------Variables------------ |
|
|
|
|
|
|
|
/// ------------Controllers------------ |
|
|
|
|
|
|
|
/// ------------Functions------------ |
|
|
|
|
|
|
|
/// ------------Api Calls------------ |
|
|
|
FutureOr<void> _getQuestionEvent(event, emit) async { |
|
|
|
await _getQuestionUseCase(event.questionParams).then( |
|
|
|
(value) { |
|
|
|
value.fold( |
|
|
|
(data) { |
|
|
|
emit(state.copyWith(getQuestionStatus: BaseComplete<QuestionEntity>(data))); |
|
|
|
}, |
|
|
|
(error) { |
|
|
|
emit(state.copyWith(getQuestionStatus: BaseError(error.errorMessage))); |
|
|
|
}, |
|
|
|
); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
} |