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.
61 lines
1.9 KiB
61 lines
1.9 KiB
import 'dart:async';
|
|
import 'package:bloc/bloc.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:hadi_hoda_flutter/core/params/question_params.dart';
|
|
import 'package:hadi_hoda_flutter/core/status/base_status.dart';
|
|
import 'package:hadi_hoda_flutter/features/question/domain/usecases/get_level_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._getLevelUseCase,
|
|
) : super(const QuestionState()) {
|
|
on<GetLevelEvent>(_getLevelEvent);
|
|
on<ChooseAnswerEvent>(_chooseAnswerEvent);
|
|
}
|
|
|
|
/// ------------UseCases------------
|
|
final GetLevelUseCase _getLevelUseCase;
|
|
|
|
/// ------------Variables------------
|
|
final List<GlobalKey> keys = [
|
|
GlobalKey(),
|
|
GlobalKey(),
|
|
GlobalKey(),
|
|
GlobalKey(),
|
|
];
|
|
|
|
|
|
/// ------------Controllers------------
|
|
|
|
/// ------------Functions------------
|
|
void startShowCase({required BuildContext context}) {
|
|
ShowCaseWidget.of(context).startShowCase([keys[1]]);
|
|
}
|
|
|
|
FutureOr<void> _chooseAnswerEvent(ChooseAnswerEvent event, Emitter<QuestionState> emit) {
|
|
emit(state.copyWith(chooseAnswer: event.answer));
|
|
}
|
|
|
|
/// ------------Api Calls------------
|
|
FutureOr<void> _getLevelEvent(GetLevelEvent event, Emitter<QuestionState> emit) async {
|
|
await _getLevelUseCase(QuestionParams(id: int.parse(event.id ?? '0'))).then(
|
|
(value) {
|
|
value.fold(
|
|
(data) {
|
|
emit(state.copyWith(
|
|
getQuestionStatus: BaseComplete(''),
|
|
levelEntity: data,
|
|
));
|
|
},
|
|
(error) {
|
|
emit(state.copyWith(getQuestionStatus: BaseError(error.errorMessage)));
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|