diff --git a/lib/features/level/presentation/bloc/level_bloc.dart b/lib/features/level/presentation/bloc/level_bloc.dart index c8b3961..7ec2351 100644 --- a/lib/features/level/presentation/bloc/level_bloc.dart +++ b/lib/features/level/presentation/bloc/level_bloc.dart @@ -26,6 +26,7 @@ class LevelBloc extends Bloc { on(_getLevelListEvent); on(_setCurrentLevelEvent); on(_startScrollEvent); + on(_chooseLevelEvent); } @override @@ -39,7 +40,7 @@ class LevelBloc extends Bloc { /// ------------Variables------------ final List bottomLocationList = [ - LevelLocation(bottom: -30, left: 30, index: 1), + LevelLocation(bottom: -20, left: 30, index: 1), LevelLocation(bottom: 50, left: 100, index: 2), LevelLocation(bottom: 150, left: 60, index: 3), LevelLocation(bottom: 210, left: 110, index: 4), @@ -173,4 +174,11 @@ class LevelBloc extends Bloc { } add(GetLevelListEvent()); } + + FutureOr _chooseLevelEvent(ChooseLevelEvent event, + Emitter emit,) { + if (event.type != LevelType.unFinished) { + emit(state.copyWith(chooseLevel: event.level)); + } + } } diff --git a/lib/features/level/presentation/bloc/level_event.dart b/lib/features/level/presentation/bloc/level_event.dart index 88f0cca..818ed6f 100644 --- a/lib/features/level/presentation/bloc/level_event.dart +++ b/lib/features/level/presentation/bloc/level_event.dart @@ -1,4 +1,5 @@ import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart'; +import 'package:hadi_hoda_flutter/features/level/presentation/ui/widgets/level_widget.dart'; sealed class LevelEvent { const LevelEvent(); @@ -9,5 +10,6 @@ class StartScrollEvent extends LevelEvent {} class SetCurrentLevelEvent extends LevelEvent {} class ChooseLevelEvent extends LevelEvent { final LevelEntity level; - const ChooseLevelEvent(this.level); + final LevelType type; + const ChooseLevelEvent(this.level, this.type); } diff --git a/lib/features/level/presentation/ui/level_page.dart b/lib/features/level/presentation/ui/level_page.dart index 482cbbe..f0500ed 100644 --- a/lib/features/level/presentation/ui/level_page.dart +++ b/lib/features/level/presentation/ui/level_page.dart @@ -6,6 +6,7 @@ import 'package:hadi_hoda_flutter/core/utils/screen_size.dart'; import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart'; import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_bloc.dart'; +import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_event.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_state.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/ui/widgets/bottom_path.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/ui/widgets/hint_level_widget.dart'; @@ -113,10 +114,15 @@ class LevelPage extends StatelessWidget { bottom: context.read().topLocationList[index].bottom, right: context.read().topLocationList[index].right, left: context.read().topLocationList[index].left, - child: LevelWidget( - level: context.read().top12LevelList[index], - type: context.read().getLevelType(index + 9), - onTap: (LevelEntity level) {}, + child: BlocBuilder( + builder: (context, state) => LevelWidget( + chooseLevel: state.chooseLevel, + level: context.read().top12LevelList[index], + type: context.read().getLevelType(index + 9), + onTap: (LevelEntity level, LevelType type) { + context.read().add(ChooseLevelEvent(level, type)); + }, + ), ), ), ), @@ -142,10 +148,17 @@ class LevelPage extends StatelessWidget { bottom: context.read().bottomLocationList[index].bottom, right: context.read().bottomLocationList[index].right, left: context.read().bottomLocationList[index].left, - child: LevelWidget( - level: context.read().bottom8LevelList[index], - type: context.read().getLevelType(index + 1), - onTap: (LevelEntity level) {}, + child: BlocBuilder( + buildWhen: (previous, current) => + previous.chooseLevel?.id != current.chooseLevel?.id, + builder: (context, state) => LevelWidget( + chooseLevel: state.chooseLevel, + level: context.read().bottom8LevelList[index], + type: context.read().getLevelType(index + 1), + onTap: (LevelEntity level, LevelType type) { + context.read().add(ChooseLevelEvent(level, type)); + }, + ), ), ), ), diff --git a/lib/features/level/presentation/ui/widgets/level_widget.dart b/lib/features/level/presentation/ui/widgets/level_widget.dart index 2850a82..c92a669 100644 --- a/lib/features/level/presentation/ui/widgets/level_widget.dart +++ b/lib/features/level/presentation/ui/widgets/level_widget.dart @@ -21,18 +21,20 @@ class LevelWidget extends StatelessWidget { const LevelWidget({ super.key, required this.level, - this.type, + required this.type, + required this.chooseLevel, this.onTap, }); - final LevelType? type; + final LevelType type; final LevelEntity level; - final Function(LevelEntity level)? onTap; + final LevelEntity? chooseLevel; + final Function(LevelEntity level, LevelType type)? onTap; @override Widget build(BuildContext context) { return InkWell( - onTap: () => onTap?.call(level), + onTap: () => onTap?.call(level, type), child: Stack( alignment: Alignment.topCenter, clipBehavior: Clip.none, @@ -51,7 +53,7 @@ class LevelWidget extends StatelessWidget { ], ), ), - if(type == LevelType.current) + if(level.id == chooseLevel?.id) Positioned( top: -20, child: MyImage( diff --git a/lib/features/question/presentation/bloc/question_bloc.dart b/lib/features/question/presentation/bloc/question_bloc.dart index e33c3bb..eda94c4 100644 --- a/lib/features/question/presentation/bloc/question_bloc.dart +++ b/lib/features/question/presentation/bloc/question_bloc.dart @@ -126,13 +126,15 @@ class QuestionBloc extends Bloc { ); if (state.currentQuestion?.order == state.levelEntity?.questions?.length) { - int currentLevel = int.parse( + int currentLevel = int.parse( LocalStorage.readData(key: MyConstants.currentLevel) ?? '1'); - ++currentLevel; - await LocalStorage.saveData( - key: MyConstants.currentLevel, - value: '$currentLevel', - ); + if (state.levelEntity?.order == currentLevel) { + ++currentLevel; + await LocalStorage.saveData( + key: MyConstants.currentLevel, + value: '$currentLevel', + ); + } } else { await playVoice(); }