From df33ad3d80995c50957b38434ece02ecf86e2e28 Mon Sep 17 00:00:00 2001 From: AmirrezaChegini Date: Wed, 29 Oct 2025 09:46:35 +0330 Subject: [PATCH] add: exit dialog --- .../about_us_dialog.dart | 4 +- lib/core/widgets/dialog/exit_dialog.dart | 103 ++++++++++++++++++ .../hadith_dialog.dart | 4 +- .../styles/dialog_background.dart} | 11 +- .../widgets/dialog/styles/dialog_button.dart | 81 ++++++++++++++ .../home/presentation/bloc/home_bloc.dart | 8 +- .../home/presentation/ui/home_page.dart | 34 +++--- .../presentation/bloc/question_bloc.dart | 2 +- 8 files changed, 224 insertions(+), 23 deletions(-) rename lib/core/widgets/{about_us_dialog => dialog}/about_us_dialog.dart (96%) create mode 100644 lib/core/widgets/dialog/exit_dialog.dart rename lib/core/widgets/{hadith_dialog => dialog}/hadith_dialog.dart (95%) rename lib/core/widgets/{about_us_dialog/styles/background.dart => dialog/styles/dialog_background.dart} (92%) create mode 100644 lib/core/widgets/dialog/styles/dialog_button.dart diff --git a/lib/core/widgets/about_us_dialog/about_us_dialog.dart b/lib/core/widgets/dialog/about_us_dialog.dart similarity index 96% rename from lib/core/widgets/about_us_dialog/about_us_dialog.dart rename to lib/core/widgets/dialog/about_us_dialog.dart index e575dd9..4ecdc78 100644 --- a/lib/core/widgets/about_us_dialog/about_us_dialog.dart +++ b/lib/core/widgets/dialog/about_us_dialog.dart @@ -7,7 +7,7 @@ import 'package:hadi_hoda_flutter/common_ui/resources/my_colors.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_text_style.dart'; import 'package:hadi_hoda_flutter/core/utils/my_localization.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; -import 'package:hadi_hoda_flutter/core/widgets/about_us_dialog/styles/background.dart'; +import 'package:hadi_hoda_flutter/core/widgets/dialog/styles/dialog_background.dart'; import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart'; Future showAboutUsDialog({required BuildContext context}) async { @@ -40,7 +40,7 @@ class AboutUsDialog extends StatelessWidget { child: Stack( clipBehavior: Clip.none, children: [ - AboutUSDialogBackground( + DialogBackground( child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ diff --git a/lib/core/widgets/dialog/exit_dialog.dart b/lib/core/widgets/dialog/exit_dialog.dart new file mode 100644 index 0000000..a75f365 --- /dev/null +++ b/lib/core/widgets/dialog/exit_dialog.dart @@ -0,0 +1,103 @@ +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:go_router/go_router.dart'; +import 'package:hadi_hoda_flutter/common_ui/resources/my_colors.dart'; +import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; +import 'package:hadi_hoda_flutter/common_ui/resources/my_text_style.dart'; +import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; +import 'package:hadi_hoda_flutter/core/widgets/dialog/styles/dialog_background.dart'; +import 'package:hadi_hoda_flutter/core/widgets/dialog/styles/dialog_button.dart'; + +Future showExitDialog({required BuildContext context}) async { + await showDialog( + context: context, + builder: (context) => ExitDialog(), + barrierColor: MyColors.purple.withValues(alpha: 0.82), + useSafeArea: false, + ); +} + +class ExitDialog extends StatelessWidget { + const ExitDialog({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: MyColors.transparent, + body: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 6, sigmaY: 6), + child: Center( + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: setSize(context: context, mobile: 18, tablet: 160) ?? 0, + ), + child: DialogBackground( + height: 260, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'want To Exit?', + style: MYTextStyle.titr0.copyWith(color: Color(0XFF322386)), + ), + Text( + 'Come back, hero!\nThe adventure isn’t over yet', + style: MYTextStyle.titr3.copyWith(color: Color(0XFF6272A9)), + textAlign: TextAlign.center, + ), + Row( + spacing: MySpaces.s20, + children: [ + Expanded( + child: DialogButton( + onTap: () { + context.pop(); + }, + height: 72, + color: Color(0XFFC0BDD3), + child: Text( + 'Cancel', + style: MYTextStyle.button2.copyWith( + shadows: [ + BoxShadow( + color: Color(0XFF9895AE), + offset: Offset(0, 3.32), + ), + ], + ), + ), + ), + ), + Expanded( + child: DialogButton( + onTap: () { + SystemNavigator.pop(); + }, + height: 72, + color: Color(0XFFD42427), + child: Text( + 'Exit', + style: MYTextStyle.button2.copyWith( + shadows: [ + BoxShadow( + color: Color(0XFFC82020), + offset: Offset(0, 3.32), + ), + ], + ), + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), + ), + ); + } +} diff --git a/lib/core/widgets/hadith_dialog/hadith_dialog.dart b/lib/core/widgets/dialog/hadith_dialog.dart similarity index 95% rename from lib/core/widgets/hadith_dialog/hadith_dialog.dart rename to lib/core/widgets/dialog/hadith_dialog.dart index 9e195b3..4e2259e 100644 --- a/lib/core/widgets/hadith_dialog/hadith_dialog.dart +++ b/lib/core/widgets/dialog/hadith_dialog.dart @@ -6,7 +6,7 @@ import 'package:hadi_hoda_flutter/common_ui/resources/my_assets.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_colors.dart'; import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; -import 'package:hadi_hoda_flutter/core/widgets/about_us_dialog/styles/background.dart'; +import 'package:hadi_hoda_flutter/core/widgets/dialog/styles/dialog_background.dart'; import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart'; import 'package:hadi_hoda_flutter/features/question/domain/entity/hadith_entity.dart'; @@ -45,7 +45,7 @@ class HadithDialog extends StatelessWidget { child: Stack( clipBehavior: Clip.none, children: [ - AboutUSDialogBackground( + DialogBackground( child: ListView.separated( itemCount: hadith.length, separatorBuilder: (context, index) => Divider( diff --git a/lib/core/widgets/about_us_dialog/styles/background.dart b/lib/core/widgets/dialog/styles/dialog_background.dart similarity index 92% rename from lib/core/widgets/about_us_dialog/styles/background.dart rename to lib/core/widgets/dialog/styles/dialog_background.dart index 2105738..099be2f 100644 --- a/lib/core/widgets/about_us_dialog/styles/background.dart +++ b/lib/core/widgets/dialog/styles/dialog_background.dart @@ -3,10 +3,15 @@ import 'package:hadi_hoda_flutter/common_ui/resources/my_spaces.dart'; import 'package:hadi_hoda_flutter/core/utils/screen_size.dart'; import 'package:hadi_hoda_flutter/core/utils/set_platform_size.dart'; -class AboutUSDialogBackground extends StatelessWidget { - const AboutUSDialogBackground({super.key, this.child}); +class DialogBackground extends StatelessWidget { + const DialogBackground({ + super.key, + this.child, + this.height = 525, + }); final Widget? child; + final double height; @override Widget build(BuildContext context) { @@ -14,7 +19,7 @@ class AboutUSDialogBackground extends StatelessWidget { clipper: _BottomShapeClipper(), child: Container( width: context.widthScreen, - height: 525, + height: height, padding: EdgeInsets.symmetric( vertical: MySpaces.s30, horizontal: setSize(context: context, mobile: MySpaces.s30, tablet: 60) ?? 0, diff --git a/lib/core/widgets/dialog/styles/dialog_button.dart b/lib/core/widgets/dialog/styles/dialog_button.dart new file mode 100644 index 0000000..fc4f160 --- /dev/null +++ b/lib/core/widgets/dialog/styles/dialog_button.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; + +class DialogButton extends StatelessWidget { + const DialogButton({ + super.key, + this.color, + this.height = 72.0, + this.child, + this.onTap, + }); + + final Color? color; + final double height; + final Widget? child; + final VoidCallback? onTap; + + @override + Widget build(BuildContext context) { + return ClipPath( + clipper: ButtonDialogClipper(), + child: Material( + type: MaterialType.transparency, + child: InkWell( + onTap: onTap, + child: Ink( + height: height, + color: color, + child: Center( + child: child, + ), + ), + ), + ), + ); + } +} + + + +class ButtonDialogClipper extends CustomClipper { + @override + Path getClip(Size size) { + final path = Path(); + path.moveTo(size.width * 0.01841077, size.height * 0.8753694); + path.cubicTo( + size.width * 0.05368083, + size.height * 1.03396, + size.width * 0.888405, + size.height * 1.04665, + size.width * 0.961125, + size.height * 0.881918); + path.cubicTo( + size.width * 1.02749, + size.height * 0.732121, + size.width * 1.00029, + size.height * 0.195965, + size.width * 0.943774, + size.height * 0.0891425); + path.cubicTo( + size.width * 0.866786, + size.height * -0.0565611, + size.width * 0.122135, + size.height * -0.00478720, + size.width * 0.0598435, + size.height * 0.109607); + path.cubicTo( + size.width * 0.00172381, + size.height * 0.216429, + size.width * -0.0181157, + size.height * 0.711249, + size.width * 0.01841077, + size.height * 0.8753694); + path.close(); + return path; + } + + @override + bool shouldReclip(CustomClipper oldClipper) { + return true; + } +} \ No newline at end of file diff --git a/lib/features/home/presentation/bloc/home_bloc.dart b/lib/features/home/presentation/bloc/home_bloc.dart index 54d9b92..6dd61de 100644 --- a/lib/features/home/presentation/bloc/home_bloc.dart +++ b/lib/features/home/presentation/bloc/home_bloc.dart @@ -7,8 +7,10 @@ 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/routers/my_routes.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/widgets/about_us_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_state.dart'; import 'package:hadi_hoda_flutter/features/level/domain/entity/total_data_entity.dart'; @@ -81,6 +83,10 @@ class HomeBloc extends Bloc { await _effectAudioService.play(); } + void onPopInvokedWithResult(bool didPop, dynamic result) { + showExitDialog(context: ContextProvider.context); + } + /// ------------Api Calls------------ FutureOr _getHomeEvent(event, emit) async {} } diff --git a/lib/features/home/presentation/ui/home_page.dart b/lib/features/home/presentation/ui/home_page.dart index c79bf5f..32dfd4f 100644 --- a/lib/features/home/presentation/ui/home_page.dart +++ b/lib/features/home/presentation/ui/home_page.dart @@ -15,21 +15,27 @@ class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - body: DecoratedBox( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage(MyAssets.backgroundHome), - fit: BoxFit.cover, + body: PopScope( + canPop: false, + onPopInvokedWithResult: context + .read() + .onPopInvokedWithResult, + child: DecoratedBox( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage(MyAssets.backgroundHome), + fit: BoxFit.cover, + ), ), - ), - child: SizedBox.expand( - child: Stack( - alignment: Alignment.center, - children: [ - _music(context), - _image(context), - _bottomBtns(context), - ], + child: SizedBox.expand( + child: Stack( + alignment: Alignment.center, + children: [ + _music(context), + _image(context), + _bottomBtns(context), + ], + ), ), ), ), diff --git a/lib/features/question/presentation/bloc/question_bloc.dart b/lib/features/question/presentation/bloc/question_bloc.dart index 3d5613f..446802b 100644 --- a/lib/features/question/presentation/bloc/question_bloc.dart +++ b/lib/features/question/presentation/bloc/question_bloc.dart @@ -12,7 +12,7 @@ import 'package:hadi_hoda_flutter/core/services/audio_service.dart'; import 'package:hadi_hoda_flutter/core/status/base_status.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/widgets/hadith_dialog/hadith_dialog.dart'; +import 'package:hadi_hoda_flutter/core/widgets/dialog/hadith_dialog.dart'; import 'package:hadi_hoda_flutter/features/level/domain/entity/level_entity.dart'; import 'package:hadi_hoda_flutter/features/question/domain/entity/answer_entity.dart'; import 'package:hadi_hoda_flutter/features/question/domain/entity/question_entity.dart';