Browse Source

fix: pop scope

pull/37/head
AmirrezaChegini 1 day ago
parent
commit
7e836151a7
  1. 3
      lib/core/routers/my_routes.dart
  2. 26
      lib/core/widgets/pop_scope/my_pop_scope.dart
  3. 6
      lib/features/home/presentation/bloc/home_bloc.dart
  4. 7
      lib/features/home/presentation/ui/home_page.dart
  5. 39
      lib/features/level/presentation/ui/level_page.dart
  6. 89
      lib/features/question/presentation/ui/question_page.dart

3
lib/core/routers/my_routes.dart

@ -96,7 +96,8 @@ GoRouter get appPages => GoRouter(
path: Routes.homePage, path: Routes.homePage,
builder: (context, state) => BlocProvider( builder: (context, state) => BlocProvider(
create: (context) => create: (context) =>
HomeBloc(locator(instanceName: MyConstants.mainAudioService),
HomeBloc(
locator(instanceName: MyConstants.mainAudioService),
locator(instanceName: MyConstants.effectAudioService), locator(instanceName: MyConstants.effectAudioService),
), ),
child: const HomePage(), child: const HomePage(),

26
lib/core/widgets/pop_scope/my_pop_scope.dart

@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:hadi_hoda_flutter/core/widgets/dialog/exit_dialog.dart';
class MyPopScope extends StatelessWidget {
const MyPopScope({super.key, required this.child});
final Widget child;
void onPopInvokedWithResult(
bool didPop,
dynamic result,
BuildContext context,
) {
showExitDialog(context: context);
}
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, result) =>
onPopInvokedWithResult(didPop, result, context),
child: child,
);
}
}

6
lib/features/home/presentation/bloc/home_bloc.dart

@ -7,10 +7,8 @@ import 'package:hadi_hoda_flutter/common_ui/resources/my_audios.dart';
import 'package:hadi_hoda_flutter/core/constants/my_constants.dart'; import 'package:hadi_hoda_flutter/core/constants/my_constants.dart';
import 'package:hadi_hoda_flutter/core/routers/my_routes.dart'; import 'package:hadi_hoda_flutter/core/routers/my_routes.dart';
import 'package:hadi_hoda_flutter/core/services/audio_service.dart'; import 'package:hadi_hoda_flutter/core/services/audio_service.dart';
import 'package:hadi_hoda_flutter/core/utils/context_provider.dart';
import 'package:hadi_hoda_flutter/core/utils/local_storage.dart'; import 'package:hadi_hoda_flutter/core/utils/local_storage.dart';
import 'package:hadi_hoda_flutter/core/widgets/dialog/about_us_dialog.dart'; import 'package:hadi_hoda_flutter/core/widgets/dialog/about_us_dialog.dart';
import 'package:hadi_hoda_flutter/core/widgets/dialog/exit_dialog.dart';
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_event.dart'; import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_event.dart';
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_state.dart'; import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_state.dart';
import 'package:hadi_hoda_flutter/features/level/domain/entity/total_data_entity.dart'; import 'package:hadi_hoda_flutter/features/level/domain/entity/total_data_entity.dart';
@ -74,10 +72,6 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
await _mainAudioService.play(); await _mainAudioService.play();
} }
void onPopInvokedWithResult(bool didPop, dynamic result) {
showExitDialog(context: ContextProvider.context);
}
/// ------------Api Calls------------ /// ------------Api Calls------------
FutureOr<void> _getHomeEvent(event, emit) async {} FutureOr<void> _getHomeEvent(event, emit) async {}
} }

7
lib/features/home/presentation/ui/home_page.dart

@ -10,6 +10,7 @@ import 'package:hadi_hoda_flutter/core/widgets/animations/slide_up_fade.dart';
import 'package:hadi_hoda_flutter/core/widgets/button/my_yellow_button.dart'; import 'package:hadi_hoda_flutter/core/widgets/button/my_yellow_button.dart';
import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart'; import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart';
import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart'; import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart';
import 'package:hadi_hoda_flutter/core/widgets/pop_scope/my_pop_scope.dart';
import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_bloc.dart'; import 'package:hadi_hoda_flutter/features/home/presentation/bloc/home_bloc.dart';
class HomePage extends StatelessWidget { class HomePage extends StatelessWidget {
@ -18,11 +19,7 @@ class HomePage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: PopScope(
canPop: false,
onPopInvokedWithResult: context
.read<HomeBloc>()
.onPopInvokedWithResult,
body: MyPopScope(
child: DecoratedBox( child: DecoratedBox(
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(

39
lib/features/level/presentation/ui/level_page.dart

@ -7,6 +7,7 @@ import 'package:hadi_hoda_flutter/core/utils/screen_size.dart';
import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart';
import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart'; import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart';
import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart'; import 'package:hadi_hoda_flutter/core/widgets/inkwell/my_inkwell.dart';
import 'package:hadi_hoda_flutter/core/widgets/pop_scope/my_pop_scope.dart';
import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.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_bloc.dart';
import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_event.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_event.dart';
@ -24,25 +25,27 @@ class LevelPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: Stack(
alignment: Alignment.center,
children: [
SingleChildScrollView(
controller: context.read<LevelBloc>().scrollController,
reverse: true,
child: Stack(
alignment: Alignment.center,
children: [
_background(),
_path(context),
_levelLocation(context),
_planets(context),
],
body: MyPopScope(
child: Stack(
alignment: Alignment.center,
children: [
SingleChildScrollView(
controller: context.read<LevelBloc>().scrollController,
reverse: true,
child: Stack(
alignment: Alignment.center,
children: [
_background(),
_path(context),
_levelLocation(context),
_planets(context),
],
),
), ),
),
_topButtons(context),
_playButton(context)
],
_topButtons(context),
_playButton(context)
],
),
), ),
); );
} }

89
lib/features/question/presentation/ui/question_page.dart

@ -7,6 +7,7 @@ import 'package:hadi_hoda_flutter/core/utils/gap.dart';
import 'package:hadi_hoda_flutter/core/utils/screen_size.dart'; import 'package:hadi_hoda_flutter/core/utils/screen_size.dart';
import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart';
import 'package:hadi_hoda_flutter/core/widgets/animations/slide_down_fade.dart'; import 'package:hadi_hoda_flutter/core/widgets/animations/slide_down_fade.dart';
import 'package:hadi_hoda_flutter/core/widgets/pop_scope/my_pop_scope.dart';
import 'package:hadi_hoda_flutter/features/question/presentation/bloc/question_bloc.dart'; import 'package:hadi_hoda_flutter/features/question/presentation/bloc/question_bloc.dart';
import 'package:hadi_hoda_flutter/features/question/presentation/bloc/question_state.dart'; import 'package:hadi_hoda_flutter/features/question/presentation/bloc/question_state.dart';
import 'package:hadi_hoda_flutter/features/question/presentation/ui/screens/diamond_screen.dart'; import 'package:hadi_hoda_flutter/features/question/presentation/ui/screens/diamond_screen.dart';
@ -23,53 +24,55 @@ class QuestionPage extends StatelessWidget {
return ShowCaseWidget( return ShowCaseWidget(
builder: (context) { builder: (context) {
return Scaffold( return Scaffold(
body: Container(
height: context.heightScreen,
width: context.widthScreen,
padding: EdgeInsets.symmetric(
horizontal: setSize(context: context,
mobile: MySpaces.s16,
tablet: MySpaces.s30) ?? 0,
vertical: setPlatform(android: MySpaces.s20) ?? 0,
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0XFF6930DA), Color(0XFF263AA1)],
body: MyPopScope(
child: Container(
height: context.heightScreen,
width: context.widthScreen,
padding: EdgeInsets.symmetric(
horizontal: setSize(context: context,
mobile: MySpaces.s16,
tablet: MySpaces.s30) ?? 0,
vertical: setPlatform(android: MySpaces.s20) ?? 0,
), ),
image: DecorationImage(
image: AssetImage(MyAssets.pattern),
scale: 3,
repeat: ImageRepeat.repeat,
colorFilter: ColorFilter.mode(
Colors.black.withValues(alpha: 0.3),
BlendMode.srcIn,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0XFF6930DA), Color(0XFF263AA1)],
),
image: DecorationImage(
image: AssetImage(MyAssets.pattern),
scale: 3,
repeat: ImageRepeat.repeat,
colorFilter: ColorFilter.mode(
Colors.black.withValues(alpha: 0.3),
BlendMode.srcIn,
),
), ),
), ),
),
child: SafeArea(
bottom: false,
child: Column(
children: [
_topButtons(context),
MySpaces.s10.gapHeight,
Expanded(
child: BlocBuilder<QuestionBloc, QuestionState>(
buildWhen: (previous, current) =>
(previous.currentQuestion?.order !=
current.currentQuestion?.order),
builder: (context, state) {
if (state.currentQuestion?.order ==
state.levelEntity?.questions?.length) {
return DiamondScreen();
} else {
return QuestionScreen();
}
},
child: SafeArea(
bottom: false,
child: Column(
children: [
_topButtons(context),
MySpaces.s10.gapHeight,
Expanded(
child: BlocBuilder<QuestionBloc, QuestionState>(
buildWhen: (previous, current) =>
(previous.currentQuestion?.order !=
current.currentQuestion?.order),
builder: (context, state) {
if (state.currentQuestion?.order ==
state.levelEntity?.questions?.length) {
return DiamondScreen();
} else {
return QuestionScreen();
}
},
),
), ),
),
],
],
),
), ),
), ),
), ),

Loading…
Cancel
Save