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. 5
      lib/features/level/presentation/ui/level_page.dart
  6. 5
      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(

5
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,7 +25,8 @@ class LevelPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: Stack(
body: MyPopScope(
child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
SingleChildScrollView( SingleChildScrollView(
@ -44,6 +46,7 @@ class LevelPage extends StatelessWidget {
_playButton(context) _playButton(context)
], ],
), ),
),
); );
} }

5
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,7 +24,8 @@ class QuestionPage extends StatelessWidget {
return ShowCaseWidget( return ShowCaseWidget(
builder: (context) { builder: (context) {
return Scaffold( return Scaffold(
body: Container(
body: MyPopScope(
child: Container(
height: context.heightScreen, height: context.heightScreen,
width: context.widthScreen, width: context.widthScreen,
padding: EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
@ -73,6 +75,7 @@ class QuestionPage extends StatelessWidget {
), ),
), ),
), ),
),
); );
}, },
); );

Loading…
Cancel
Save