|
|
@ -40,7 +40,7 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
Future<void> close() { |
|
|
Future<void> close() { |
|
|
ShowcaseView.get().unregister(); |
|
|
|
|
|
|
|
|
unRegisterShowCase(); |
|
|
return super.close(); |
|
|
return super.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -63,7 +63,6 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
'guide_key': GlobalKey(), |
|
|
'guide_key': GlobalKey(), |
|
|
}; |
|
|
}; |
|
|
late final Stream<double> volumeStream; |
|
|
late final Stream<double> volumeStream; |
|
|
bool isPlaying = false; |
|
|
|
|
|
|
|
|
|
|
|
/// ------------Controllers------------ |
|
|
/// ------------Controllers------------ |
|
|
final AudioService _mainAudioService; |
|
|
final AudioService _mainAudioService; |
|
|
@ -71,15 +70,25 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
|
|
|
|
|
|
/// ------------Functions------------ |
|
|
/// ------------Functions------------ |
|
|
void registerShowCase() { |
|
|
void registerShowCase() { |
|
|
|
|
|
try { |
|
|
ShowcaseView.register( |
|
|
ShowcaseView.register( |
|
|
onStart: (showcaseIndex, key) { |
|
|
onStart: (showcaseIndex, key) { |
|
|
LocalStorage.saveData(key: MyConstants.firstShowcase, value: 'true'); |
|
|
LocalStorage.saveData(key: MyConstants.firstShowcase, value: 'true'); |
|
|
}, |
|
|
}, |
|
|
); |
|
|
); |
|
|
|
|
|
} catch (_) {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void unRegisterShowCase() { |
|
|
|
|
|
try { |
|
|
|
|
|
ShowcaseView.get().unregister(); |
|
|
|
|
|
} catch (_) {} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void startShowcase() { |
|
|
void startShowcase() { |
|
|
if (LocalStorage.readData(key: MyConstants.firstShowcase) != 'true') { |
|
|
if (LocalStorage.readData(key: MyConstants.firstShowcase) != 'true') { |
|
|
|
|
|
try { |
|
|
ShowcaseView.get().startShowCase([ |
|
|
ShowcaseView.get().startShowCase([ |
|
|
showCaseKey['answer_key_1']!, |
|
|
showCaseKey['answer_key_1']!, |
|
|
showCaseKey['notif_key_0']!, |
|
|
showCaseKey['notif_key_0']!, |
|
|
@ -87,11 +96,11 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
showCaseKey['hadith_key']!, |
|
|
showCaseKey['hadith_key']!, |
|
|
showCaseKey['guide_key']!, |
|
|
showCaseKey['guide_key']!, |
|
|
]); |
|
|
]); |
|
|
|
|
|
} catch (_) {} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void showHadith({required BuildContext context}) { |
|
|
void showHadith({required BuildContext context}) { |
|
|
if(isPlaying) return; |
|
|
|
|
|
showHadithDialog( |
|
|
showHadithDialog( |
|
|
context: context, |
|
|
context: context, |
|
|
hadith: state.levelEntity?.hadith ?? [], |
|
|
hadith: state.levelEntity?.hadith ?? [], |
|
|
@ -112,8 +121,10 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> stopMusic() async { |
|
|
Future<void> stopMusic() async { |
|
|
await _mainAudioService.stop(); |
|
|
|
|
|
await _mainAudioService.setLoopMode(isLoop: false); |
|
|
|
|
|
|
|
|
await Future.wait([ |
|
|
|
|
|
_mainAudioService.stop(), |
|
|
|
|
|
_mainAudioService.setLoopMode(isLoop: false), |
|
|
|
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> playCorrectAudio() async { |
|
|
Future<void> playCorrectAudio() async { |
|
|
@ -134,6 +145,7 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
Future<void> playQuestionAudio() async { |
|
|
Future<void> playQuestionAudio() async { |
|
|
await _mainAudioService.setAudio(filePath: state.currentQuestion?.audio); |
|
|
await _mainAudioService.setAudio(filePath: state.currentQuestion?.audio); |
|
|
await _mainAudioService.play(); |
|
|
await _mainAudioService.play(); |
|
|
|
|
|
await showQueueAnswer(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> changeMute() async { |
|
|
Future<void> changeMute() async { |
|
|
@ -143,21 +155,41 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
]); |
|
|
]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<void> showQueueAnswer() async { |
|
|
|
|
|
final List<AnswerEntity> answers = state.currentQuestion?.answers ?? []; |
|
|
|
|
|
if (answers.isNotEmpty) { |
|
|
|
|
|
answers.removeWhere((e) => e.imageId == null); |
|
|
|
|
|
} |
|
|
|
|
|
for (final answer in answers) { |
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 500), () async { |
|
|
|
|
|
if (MyContext.get.mounted) { |
|
|
|
|
|
await showAnswerDialog( |
|
|
|
|
|
context: MyContext.get, |
|
|
|
|
|
answerEntity: answer, |
|
|
|
|
|
autoClose: true, |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Future<void> showAnswerDialog({ |
|
|
Future<void> showAnswerDialog({ |
|
|
required BuildContext context, |
|
|
required BuildContext context, |
|
|
required AnswerEntity answerEntity, |
|
|
required AnswerEntity answerEntity, |
|
|
|
|
|
bool showConfetti = false, |
|
|
|
|
|
bool autoClose = false, |
|
|
}) async { |
|
|
}) async { |
|
|
Navigator.of(context).push( |
|
|
|
|
|
|
|
|
await Navigator.of(context).push( |
|
|
HeroDialogRoute( |
|
|
HeroDialogRoute( |
|
|
builder: (dialogContext) { |
|
|
builder: (dialogContext) { |
|
|
return AnswerScreen( |
|
|
return AnswerScreen( |
|
|
answerEntity: answerEntity, |
|
|
answerEntity: answerEntity, |
|
|
onNotifTap: (answer) => playAnswerAudio(audio: answer.audio), |
|
|
|
|
|
|
|
|
showConfetti: showConfetti, |
|
|
|
|
|
autoClose: autoClose, |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
|
), |
|
|
), |
|
|
); |
|
|
); |
|
|
playAnswerAudio(audio: answerEntity.audio); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> getNextLevelEvent({required BuildContext context}) async { |
|
|
Future<void> getNextLevelEvent({required BuildContext context}) async { |
|
|
@ -213,17 +245,12 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
|
|
|
|
|
|
if (event.chooseCorrectAnswer) { |
|
|
if (event.chooseCorrectAnswer) { |
|
|
playCorrectAudio(); |
|
|
playCorrectAudio(); |
|
|
await Navigator.of(MyContext.get).push( |
|
|
|
|
|
HeroDialogRoute( |
|
|
|
|
|
builder: (dialogContext) { |
|
|
|
|
|
return AnswerScreen( |
|
|
|
|
|
|
|
|
await showAnswerDialog( |
|
|
|
|
|
context: MyContext.get, |
|
|
answerEntity: state.currentQuestion?.answers?.singleWhere((e) => |
|
|
answerEntity: state.currentQuestion?.answers?.singleWhere((e) => |
|
|
e.order == event.correctAnswer) ?? AnswerEntity(), |
|
|
e.order == event.correctAnswer) ?? AnswerEntity(), |
|
|
showConfetti: true, |
|
|
showConfetti: true, |
|
|
); |
|
|
); |
|
|
}, |
|
|
|
|
|
), |
|
|
|
|
|
); |
|
|
|
|
|
await Future.delayed(Duration(seconds: 1), () async { |
|
|
await Future.delayed(Duration(seconds: 1), () async { |
|
|
final QuestionEntity? findPreQuestion = state.currentQuestion; |
|
|
final QuestionEntity? findPreQuestion = state.currentQuestion; |
|
|
final int findIndex = (findPreQuestion?.order ?? 1); |
|
|
final int findIndex = (findPreQuestion?.order ?? 1); |
|
|
@ -245,7 +272,7 @@ class QuestionBloc extends Bloc<QuestionEvent, QuestionState> { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
playQuestionAudio(); |
|
|
|
|
|
|
|
|
await playQuestionAudio(); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
|
|