diff --git a/lib/core/routers/my_routes.dart b/lib/core/routers/my_routes.dart index bec75cf..0a7c063 100644 --- a/lib/core/routers/my_routes.dart +++ b/lib/core/routers/my_routes.dart @@ -96,7 +96,8 @@ GoRouter get appPages => GoRouter( path: Routes.homePage, builder: (context, state) => BlocProvider( create: (context) => - HomeBloc(locator(instanceName: MyConstants.mainAudioService), + HomeBloc( + locator(instanceName: MyConstants.mainAudioService), locator(instanceName: MyConstants.effectAudioService), ), child: const HomePage(), diff --git a/lib/core/widgets/dialog/hadith_dialog.dart b/lib/core/widgets/dialog/hadith_dialog.dart index 4e2259e..0191fce 100644 --- a/lib/core/widgets/dialog/hadith_dialog.dart +++ b/lib/core/widgets/dialog/hadith_dialog.dart @@ -5,6 +5,8 @@ import 'package:go_router/go_router.dart'; 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/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/dialog/styles/dialog_background.dart'; import 'package:hadi_hoda_flutter/core/widgets/images/my_image.dart'; @@ -46,22 +48,50 @@ class HadithDialog extends StatelessWidget { clipBehavior: Clip.none, children: [ DialogBackground( - child: ListView.separated( - itemCount: hadith.length, - separatorBuilder: (context, index) => Divider( - height: 40, - thickness: 1, - endIndent: MySpaces.s20, - indent: MySpaces.s20, - color: Color(0xFFC2BDE4), - ), - itemBuilder: (context, index) => Text( - hadith[index].hadithText ?? '', - ), + child: Builder( + builder: (context) { + if(hadith.isNotEmpty){ + return ListView.separated( + itemCount: hadith.length, + separatorBuilder: (context, index) => Divider( + height: 40, + thickness: 1, + endIndent: MySpaces.s20, + indent: MySpaces.s20, + color: Color(0xFFC2BDE4), + ), + itemBuilder: (context, index) => Text.rich( + TextSpan( + text: '${hadith[index].narratorName ?? ''}:\n', + style: MYTextStyle.titr1.copyWith( + color: Color(0XFF494178), + ), + children: [ + TextSpan( + text: hadith[index].hadithText, + style: MYTextStyle.matn1.copyWith( + color: Color(0XFF494178), + ), + ), + ], + ), + ), + ); + } else { + return Center( + child: Text( + context.translate.no_hadith, + style: MYTextStyle.titr4.copyWith( + color: Color(0XFF494178), + ), + ), + ); + } + }, ), ), - Positioned( - right: setSize(context: context, mobile: 30, tablet: 40), + PositionedDirectional( + end: setSize(context: context, mobile: 30, tablet: 40), top: -12, child: GestureDetector( onTap: context.pop, diff --git a/lib/core/widgets/pop_scope/my_pop_scope.dart b/lib/core/widgets/pop_scope/my_pop_scope.dart new file mode 100644 index 0000000..96b98da --- /dev/null +++ b/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, + ); + } +} diff --git a/lib/features/home/presentation/bloc/home_bloc.dart b/lib/features/home/presentation/bloc/home_bloc.dart index 2ae4457..596352e 100644 --- a/lib/features/home/presentation/bloc/home_bloc.dart +++ b/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/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/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'; @@ -74,10 +72,6 @@ class HomeBloc extends Bloc { await _mainAudioService.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 1006553..e1aaa72 100644 --- a/lib/features/home/presentation/ui/home_page.dart +++ b/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/images/my_image.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'; class HomePage extends StatelessWidget { @@ -18,11 +19,7 @@ class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - body: PopScope( - canPop: false, - onPopInvokedWithResult: context - .read() - .onPopInvokedWithResult, + body: MyPopScope( child: DecoratedBox( decoration: BoxDecoration( image: DecorationImage( diff --git a/lib/features/level/presentation/ui/level_page.dart b/lib/features/level/presentation/ui/level_page.dart index 436090e..f52b34c 100644 --- a/lib/features/level/presentation/ui/level_page.dart +++ b/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/widgets/images/my_image.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/presentation/bloc/level_bloc.dart'; import 'package:hadi_hoda_flutter/features/level/presentation/bloc/level_event.dart'; @@ -24,25 +25,27 @@ class LevelPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - body: Stack( - alignment: Alignment.center, - children: [ - SingleChildScrollView( - controller: context.read().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().scrollController, + reverse: true, + child: Stack( + alignment: Alignment.center, + children: [ + _background(), + _path(context), + _levelLocation(context), + _planets(context), + ], + ), ), - ), - _topButtons(context), - _playButton(context) - ], + _topButtons(context), + _playButton(context) + ], + ), ), ); } diff --git a/lib/features/question/presentation/ui/question_page.dart b/lib/features/question/presentation/ui/question_page.dart index c7a8ebb..75faf47 100644 --- a/lib/features/question/presentation/ui/question_page.dart +++ b/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/set_platform_size.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_state.dart'; import 'package:hadi_hoda_flutter/features/question/presentation/ui/screens/diamond_screen.dart'; @@ -23,53 +24,55 @@ class QuestionPage extends StatelessWidget { return ShowCaseWidget( builder: (context) { 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( - 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( + 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(); + } + }, + ), ), - ), - ], + ], + ), ), ), ), diff --git a/lib/features/question/presentation/ui/screens/diamond_screen.dart b/lib/features/question/presentation/ui/screens/diamond_screen.dart index c6f222d..b745169 100644 --- a/lib/features/question/presentation/ui/screens/diamond_screen.dart +++ b/lib/features/question/presentation/ui/screens/diamond_screen.dart @@ -42,7 +42,7 @@ class DiamondScreen extends StatelessWidget { ), MyImage( image: MyAssets.diamondBig, - size: setSize(context: context, mobile: 200, tablet: 300), + size: setSize(context: context, tablet: 300), ), Positioned( bottom: setSize( diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 82b4f68..8cd72d7 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -29,5 +29,6 @@ "exit_dialog_desc": "Come back, hero!\nThe adventure isn’t over yet", "cancel": "Cancel", "exit": "Exit", - "play": "PLAY" + "play": "PLAY", + "no_hadith": "There isn't any hadith for this question" } \ No newline at end of file diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 1e1258b..5458599 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -279,6 +279,12 @@ abstract class AppLocalizations { /// In en, this message translates to: /// **'PLAY'** String get play; + + /// No description provided for @no_hadith. + /// + /// In en, this message translates to: + /// **'There isn\'t any hadith for this question'** + String get no_hadith; } class _AppLocalizationsDelegate diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 95c2a37..cdf29bf 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -106,4 +106,7 @@ class AppLocalizationsEn extends AppLocalizations { @override String get play => 'PLAY'; + + @override + String get no_hadith => 'There isn\'t any hadith for this question'; }