From fb6070742a167e3f966eea1c8888eb9da1db4115 Mon Sep 17 00:00:00 2001 From: Yassin Date: Sun, 1 Dec 2024 21:46:39 +0200 Subject: [PATCH] fix: Resolve pop-up issue when selecting Listening mode - updated `_handleNavigation` method in `quran_mode_selection_screen.dart` to use `async/await` for ensuring proper completion of Quran mode selection before navigation. - fixed unexpected pop-ups by adjusting the handling of the `moshafType` state in `download_quran_popup.dart`. - improved navigation flow for both Reading and Listening modes, ensuring seamless user experience. --- .../quran/page/quran_mode_selection_screen.dart | 6 +++--- .../pages/quran/widget/download_quran_popup.dart | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/src/pages/quran/page/quran_mode_selection_screen.dart b/lib/src/pages/quran/page/quran_mode_selection_screen.dart index 093ebdec..fe66126d 100644 --- a/lib/src/pages/quran/page/quran_mode_selection_screen.dart +++ b/lib/src/pages/quran/page/quran_mode_selection_screen.dart @@ -80,12 +80,12 @@ class _QuranModeSelectionState extends ConsumerState { } } - void _handleNavigation(int index) { + Future _handleNavigation(int index) async { if (index == 0) { - ref.read(quranNotifierProvider.notifier).selectModel(QuranMode.reading); + await ref.read(quranNotifierProvider.notifier).selectModel(QuranMode.reading); Navigator.pushReplacementNamed(context, Routes.quranReading); } else { - ref.read(quranNotifierProvider.notifier).selectModel(QuranMode.listening); + await ref.read(quranNotifierProvider.notifier).selectModel(QuranMode.listening); Navigator.pushReplacementNamed(context, Routes.quranReciter); } } diff --git a/lib/src/pages/quran/widget/download_quran_popup.dart b/lib/src/pages/quran/widget/download_quran_popup.dart index 26ea12b8..bc6db853 100644 --- a/lib/src/pages/quran/widget/download_quran_popup.dart +++ b/lib/src/pages/quran/widget/download_quran_popup.dart @@ -125,7 +125,6 @@ class _DownloadQuranDialogState extends ConsumerState { onPressed: () async { final notifier = ref.read(downloadQuranNotifierProvider.notifier); final moshafType = ref.watch(moshafTypeNotifierProvider); - ref.read(moshafTypeNotifierProvider).maybeWhen( orElse: () {}, data: (state) async { @@ -211,7 +210,18 @@ class _DownloadQuranDialogState extends ConsumerState { actions: [ TextButton( onPressed: () { - Navigator.pop(context); + final moshafType = ref.watch(moshafTypeNotifierProvider); + moshafType.when( + data: (data) { + if (data.isFirstTime) { + Navigator.popUntil(context, (route) => route.isFirst); + } else { + Navigator.pop(context); + } + }, + error: (_, __) {}, + loading: () {}, + ); }, child: Text(S.of(context).cancel), ),