You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
import 'dart:async';
|
|
import 'package:bloc/bloc.dart';
|
|
import 'package:flutter/cupertino.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';
|
|
import 'package:showcaseview/showcaseview.dart';
|
|
|
|
class QuestionBloc extends Bloc<QuestionEvent, QuestionState> {
|
|
/// ------------constructor------------
|
|
QuestionBloc(
|
|
this._getQuestionUseCase,
|
|
) : super(const QuestionState()) {
|
|
on<GetQuestionEvent>(_getQuestionEvent);
|
|
}
|
|
|
|
/// ------------UseCases------------
|
|
final GetQuestionUseCase _getQuestionUseCase;
|
|
|
|
/// ------------Variables------------
|
|
final List<GlobalKey> keys = [
|
|
GlobalKey(),
|
|
GlobalKey(),
|
|
GlobalKey(),
|
|
GlobalKey(),
|
|
];
|
|
|
|
/// ------------Controllers------------
|
|
|
|
/// ------------Functions------------
|
|
void startShowCase({required BuildContext context}) {
|
|
ShowCaseWidget.of(context).startShowCase([keys[1]]);
|
|
}
|
|
|
|
/// ------------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)));
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|