Skip to content

Commit

Permalink
hotfix: Improve Quran Mode Selection and Download Flow
Browse files Browse the repository at this point in the history
- Convert _handleNavigation method in QuranModeSelectionScreen to async
- Add await to selectModel calls to ensure state is properly updated before navigation
- Refactor download_quran_popup.dart navigation logic for first-time download scenario
  • Loading branch information
YassinNouh21 committed Dec 1, 2024
1 parent 69e6049 commit eeff267
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/src/pages/quran/page/quran_mode_selection_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ class _QuranModeSelectionState extends ConsumerState<QuranModeSelection> {
}
}

void _handleNavigation(int index) {
Future<void> _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);
}
}
Expand Down
14 changes: 12 additions & 2 deletions lib/src/pages/quran/widget/download_quran_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class _DownloadQuranDialogState extends ConsumerState<DownloadQuranDialog> {
onPressed: () async {
final notifier = ref.read(downloadQuranNotifierProvider.notifier);
final moshafType = ref.watch(moshafTypeNotifierProvider);

ref.read(moshafTypeNotifierProvider).maybeWhen(
orElse: () {},
data: (state) async {
Expand Down Expand Up @@ -211,7 +210,18 @@ class _DownloadQuranDialogState extends ConsumerState<DownloadQuranDialog> {
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),
),
Expand Down

0 comments on commit eeff267

Please sign in to comment.