From e4d87b24963d5ec737b7f60db6d0c1cbd0b165f5 Mon Sep 17 00:00:00 2001 From: Yassin Date: Thu, 5 Dec 2024 23:12:44 +0200 Subject: [PATCH 01/18] refactor: Optimize Quran Reading Auto-Scroll and Add Loading Indicator --- .../quran/reading/quran_reading_screen.dart | 58 +++++++++----- .../auto_reading/auto_reading_notifier.dart | 75 ++++++++++++------- .../auto_reading/auto_reading_state.dart | 8 ++ .../quran/reading/quran_reading_notifer.dart | 10 ++- 4 files changed, 103 insertions(+), 48 deletions(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index fa2ff88dc..d6e10f0b6 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -61,6 +61,7 @@ class FocusNodes { class AutoScrollViewStrategy implements QuranViewStrategy { final AutoScrollState autoScrollState; + final int preloadDistance = 3; // Adjust preload distance for performance AutoScrollViewStrategy(this.autoScrollState); @@ -68,29 +69,46 @@ class AutoScrollViewStrategy implements QuranViewStrategy { Widget buildView(QuranReadingState state, WidgetRef ref, BuildContext context) { final scalingFactor = autoScrollState.fontSize; - return ListView.builder( - physics: NeverScrollableScrollPhysics(), - controller: autoScrollState.scrollController, - itemCount: state.totalPages, - itemBuilder: (context, index) { - return GestureDetector( - onTap: () { - final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); - if (autoScrollState.isPlaying) { - autoScrollNotifier.pauseAutoScroll(); - } else { - autoScrollNotifier.resumeAutoScroll(); - } + return Stack( + children: [ + ListView.builder( + key: PageStorageKey('auto_scroll_list'), // Add key to preserve scroll position + physics: NeverScrollableScrollPhysics(), + controller: autoScrollState.scrollController, + itemCount: state.totalPages, + cacheExtent: MediaQuery.of(context).size.height * preloadDistance, // Reduce cache extent + itemExtent: MediaQuery.of(context).size.height * scalingFactor, // Use itemExtent for fixed height + addRepaintBoundaries: true, // Optimize repaint boundaries + itemBuilder: (context, index) { + return GestureDetector( + onTap: () { + final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); + if (autoScrollState.isPlaying) { + autoScrollNotifier.pauseAutoScroll(); + } else { + autoScrollNotifier.resumeAutoScroll(); + } + }, + child: SizedBox( + width: MediaQuery.of(context).size.width * scalingFactor, + height: MediaQuery.of(context).size.height * scalingFactor, + child: SvgPictureWidget( + svgPicture: state.svgs[index], + ), + ), + ); }, - child: SizedBox( - width: MediaQuery.of(context).size.width * scalingFactor, - height: MediaQuery.of(context).size.height * scalingFactor, - child: SvgPictureWidget( - svgPicture: state.svgs[index], + ), + if (autoScrollState.isLoading) + Container( + color: Colors.white.withOpacity(0.7), + child: Center( + child: CircularProgressIndicator( + color: Theme.of(context).primaryColor, + ), ), ), - ); - }, + ], ); } diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index 1ebe00963..3c646fd24 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mawaqit/src/state_management/quran/reading/auto_reading/auto_reading_state.dart'; +import 'package:mawaqit/src/state_management/quran/reading/quran_reading_notifer.dart'; class AutoScrollNotifier extends AutoDisposeNotifier { Timer? _autoScrollTimer; @@ -40,44 +41,33 @@ class AutoScrollNotifier extends AutoDisposeNotifier { Future startAutoScroll(int currentPage, double pageHeight) async { _autoScrollTimer?.cancel(); - // Store the current scroll position before making changes - double? currentScrollPosition; - if (scrollController.hasClients) { - currentScrollPosition = scrollController.offset; - } - state = state.copyWith( isSinglePageView: true, + isLoading: true, + currentPage: currentPage, // Set initial page ); // Ensure the ListView is built - await Future.delayed(Duration(milliseconds: 50)); + await Future.delayed(Duration(milliseconds: 500)); - // Restore the previous scroll position if it exists, - // otherwise jump to the current page if (scrollController.hasClients) { - if (currentScrollPosition != null) { - scrollController.jumpTo(currentScrollPosition); - } else { - final offset = (currentPage - 1) * pageHeight; - scrollController.jumpTo(offset); - } + final offset = (currentPage - 1) * pageHeight; + scrollController.jumpTo(offset); } + state = state.copyWith( + isLoading: false, + isPlaying: true, + ); + _startScrolling(); } void _startScrolling() { - // Only start scrolling if we're in playing state if (!state.isPlaying) return; - state = state.copyWith( - isPlaying: true, - ); - const duration = Duration(milliseconds: 50); _autoScrollTimer = Timer.periodic(duration, (timer) { - // Check if we should be scrolling if (!state.isPlaying) { timer.cancel(); return; @@ -92,17 +82,52 @@ class AutoScrollNotifier extends AutoDisposeNotifier { stopAutoScroll(); } else { scrollController.jumpTo(currentScroll + delta); + + // Update current page during scrolling + final pageHeight = scrollController.position.viewportDimension; + final newPage = (currentScroll / pageHeight).ceil() + 1; + if (newPage != state.currentPage) { + state = state.copyWith(currentPage: newPage); + } } } }); } - void stopAutoScroll() { + void stopAutoScroll() async { _autoScrollTimer?.cancel(); _autoScrollTimer = null; - state = state.copyWith( - isSinglePageView: false, - ); + + // Calculate current page before switching views + if (scrollController.hasClients) { + final pageHeight = scrollController.position.viewportDimension; + final currentPage = (scrollController.offset / pageHeight).ceil() + 1; + + // First update state to disable auto-scroll + state = state.copyWith( + isSinglePageView: false, + isPlaying: false, + ); + + // Then update the page after a small delay to allow view transition + await Future.delayed(Duration(milliseconds: 100)); + + // Update QuranReadingState with current page + try { + await ref.read(quranReadingNotifierProvider.notifier).updatePage( + currentPage, + isPortairt: false, + ); + } catch (e) { + // Handle error silently or show a user-friendly message + print('Error updating page: $e'); + } + } else { + state = state.copyWith( + isSinglePageView: false, + isPlaying: false, + ); + } } void changeSpeed(double newSpeed) { diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart index e237e9379..9f195d31c 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart @@ -8,6 +8,8 @@ class AutoScrollState { final double maxFontSize; final ScrollController scrollController; final bool isPlaying; + final bool isLoading; + final int currentPage; AutoScrollState({ required this.scrollController, @@ -17,6 +19,8 @@ class AutoScrollState { this.fontSize = 1.0, this.maxFontSize = 3.0, this.isPlaying = false, + this.isLoading = false, + this.currentPage = 1, }); bool get isAutoScrolling => isSinglePageView; @@ -31,6 +35,8 @@ class AutoScrollState { double? maxFontSize, ScrollController? scrollController, bool? isPlaying, + bool? isLoading, + int? currentPage, }) { return AutoScrollState( isSinglePageView: isSinglePageView ?? this.isSinglePageView, @@ -40,6 +46,8 @@ class AutoScrollState { maxFontSize: maxFontSize ?? this.maxFontSize, scrollController: scrollController ?? this.scrollController, isPlaying: isPlaying ?? this.isPlaying, + isLoading: isLoading ?? this.isLoading, + currentPage: currentPage ?? this.currentPage, ); } diff --git a/lib/src/state_management/quran/reading/quran_reading_notifer.dart b/lib/src/state_management/quran/reading/quran_reading_notifer.dart index b23bcc3eb..99fbb98f3 100644 --- a/lib/src/state_management/quran/reading/quran_reading_notifer.dart +++ b/lib/src/state_management/quran/reading/quran_reading_notifer.dart @@ -77,9 +77,13 @@ class QuranReadingNotifier extends AutoDisposeAsyncNotifier { final currentState = state.value!; if (page >= 0 && page < currentState.totalPages) { await _saveLastReadPage(page); - !isPortairt - ? currentState.pageController.jumpToPage((page / 2).floor()) - : currentState.pageController.jumpToPage(page); // Jump to the selected page + + if (currentState.pageController.hasClients) { + !isPortairt + ? currentState.pageController.jumpToPage((page / 2).floor()) + : currentState.pageController.jumpToPage(page); + } + final newSurahName = _getCurrentSurahName(page, currentState.suwar); return currentState.copyWith( From 80707a1b75238db4c1e38180eaac1ed4487acfa5 Mon Sep 17 00:00:00 2001 From: Yassin Date: Sat, 7 Dec 2024 08:43:15 +0200 Subject: [PATCH 02/18] fix: stopping the auto-scroll causes an unwanted page advancement --- .../quran/reading/auto_reading/auto_reading_notifier.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index 3c646fd24..e2e35be30 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -101,7 +101,9 @@ class AutoScrollNotifier extends AutoDisposeNotifier { // Calculate current page before switching views if (scrollController.hasClients) { final pageHeight = scrollController.position.viewportDimension; - final currentPage = (scrollController.offset / pageHeight).ceil() + 1; + // Use floor instead of ceil and don't add 1 to stay on current page + // if scroll hasn't moved significantly + final currentPage = (scrollController.offset / pageHeight).floor() + 1; // First update state to disable auto-scroll state = state.copyWith( From 33c39133333d328b833ff3c0bb45b816de3324e8 Mon Sep 17 00:00:00 2001 From: Yassin Date: Mon, 9 Dec 2024 00:02:05 +0200 Subject: [PATCH 03/18] fix: initializing the scrollController with the correct offset --- .../auto_reading/auto_reading_notifier.dart | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index e2e35be30..eb81e2a26 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -51,8 +51,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier { await Future.delayed(Duration(milliseconds: 500)); if (scrollController.hasClients) { - final offset = (currentPage - 1) * pageHeight; - scrollController.jumpTo(offset); + _initializeScrollController(currentPage, pageHeight); } state = state.copyWith( @@ -63,6 +62,12 @@ class AutoScrollNotifier extends AutoDisposeNotifier { _startScrolling(); } + void _initializeScrollController(int currentPage, double pageHeight) { + final pageOffset = (currentPage - 1) * pageHeight; + // Set initial offset to correct position, account for rotation if necessary + scrollController.jumpTo(pageOffset); + } + void _startScrolling() { if (!state.isPlaying) return; @@ -85,7 +90,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier { // Update current page during scrolling final pageHeight = scrollController.position.viewportDimension; - final newPage = (currentScroll / pageHeight).ceil() + 1; + final newPage = _calculateCurrentPage(scrollController, pageHeight); if (newPage != state.currentPage) { state = state.copyWith(currentPage: newPage); } @@ -94,6 +99,18 @@ class AutoScrollNotifier extends AutoDisposeNotifier { }); } + // Function to calculate current page during scrolling + int _calculateCurrentPage(ScrollController scrollController, double pageHeight) { + final viewportOffset = scrollController.offset % pageHeight; + if (viewportOffset < (pageHeight / 2)) { + // Scrolled to the left, check if it's possible to navigate to the previous page + return (scrollController.offset / pageHeight).floor() + 1; + } else { + // Scrolled to the right, check if it's possible to navigate to the next page + return (scrollController.offset / pageHeight).ceil() + 1; + } + } + void stopAutoScroll() async { _autoScrollTimer?.cancel(); _autoScrollTimer = null; @@ -103,8 +120,8 @@ class AutoScrollNotifier extends AutoDisposeNotifier { final pageHeight = scrollController.position.viewportDimension; // Use floor instead of ceil and don't add 1 to stay on current page // if scroll hasn't moved significantly - final currentPage = (scrollController.offset / pageHeight).floor() + 1; - + final currentPage = _calculateCurrentPage(scrollController, pageHeight); + // First update state to disable auto-scroll state = state.copyWith( isSinglePageView: false, @@ -113,7 +130,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier { // Then update the page after a small delay to allow view transition await Future.delayed(Duration(milliseconds: 100)); - + // Update QuranReadingState with current page try { await ref.read(quranReadingNotifierProvider.notifier).updatePage( From c1eee724225a2d8d7e401a9dac0eab3900082707 Mon Sep 17 00:00:00 2001 From: Ghassen Ben Zahra Date: Wed, 11 Dec 2024 15:47:56 +0100 Subject: [PATCH 04/18] fix exit on scroll to correct page --- .../pages/quran/reading/quran_reading_screen.dart | 2 +- .../widget/quran_floating_action_buttons.dart | 15 +++++++++++++-- .../auto_reading/auto_reading_notifier.dart | 10 +++++----- .../quran/reading/quran_reading_notifer.dart | 6 +++--- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index d6e10f0b6..4f55f08df 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -72,7 +72,7 @@ class AutoScrollViewStrategy implements QuranViewStrategy { return Stack( children: [ ListView.builder( - key: PageStorageKey('auto_scroll_list'), // Add key to preserve scroll position + key: PageStorageKey('auto_scroll_list'), // Add key to preserve scroll position physics: NeverScrollableScrollPhysics(), controller: autoScrollState.scrollController, itemCount: state.totalPages, diff --git a/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart b/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart index 3064b1944..da0b381fb 100644 --- a/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart +++ b/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart @@ -54,6 +54,7 @@ class _QuranFloatingActionControlsState extends ConsumerState { isPortrait: widget.isPortrait, icon: Icons.close, onPressed: () { - ref.read(autoScrollNotifierProvider.notifier).stopAutoScroll(); + ref.read(autoScrollNotifierProvider.notifier).stopAutoScroll( + isPortairt: widget.isPortrait, + quranReadingState: widget.quranReadingState); }, tooltip: 'Exit Auto-Scroll', ); @@ -327,9 +333,10 @@ class _ActionButton extends StatelessWidget { class _OrientationToggleButton extends ConsumerWidget { final FocusNode switchScreenViewFocusNode; - + final int currentPage; const _OrientationToggleButton({ required this.switchScreenViewFocusNode, + required this.currentPage, }); @override @@ -356,6 +363,10 @@ class _OrientationToggleButton extends ConsumerWidget { size: iconSize, ), onPressed: () { + ref + .read(quranReadingNotifierProvider.notifier) + .updatePage(currentPage); + ref.read(quranReadingNotifierProvider.notifier).toggleRotation(); }, heroTag: null, diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index eb81e2a26..872d7b6e7 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -4,6 +4,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mawaqit/src/state_management/quran/reading/auto_reading/auto_reading_state.dart'; import 'package:mawaqit/src/state_management/quran/reading/quran_reading_notifer.dart'; +import 'package:mawaqit/src/state_management/quran/reading/quran_reading_state.dart'; class AutoScrollNotifier extends AutoDisposeNotifier { Timer? _autoScrollTimer; @@ -111,7 +112,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier { } } - void stopAutoScroll() async { + void stopAutoScroll({QuranReadingState? quranReadingState, bool isPortairt = false}) async { _autoScrollTimer?.cancel(); _autoScrollTimer = null; @@ -121,7 +122,6 @@ class AutoScrollNotifier extends AutoDisposeNotifier { // Use floor instead of ceil and don't add 1 to stay on current page // if scroll hasn't moved significantly final currentPage = _calculateCurrentPage(scrollController, pageHeight); - // First update state to disable auto-scroll state = state.copyWith( isSinglePageView: false, @@ -134,9 +134,9 @@ class AutoScrollNotifier extends AutoDisposeNotifier { // Update QuranReadingState with current page try { await ref.read(quranReadingNotifierProvider.notifier).updatePage( - currentPage, - isPortairt: false, - ); + !isPortairt ? currentPage : quranReadingState!.currentPage, + isPortairt: isPortairt, + ); } catch (e) { // Handle error silently or show a user-friendly message print('Error updating page: $e'); diff --git a/lib/src/state_management/quran/reading/quran_reading_notifer.dart b/lib/src/state_management/quran/reading/quran_reading_notifer.dart index 99fbb98f3..4da6bbb68 100644 --- a/lib/src/state_management/quran/reading/quran_reading_notifer.dart +++ b/lib/src/state_management/quran/reading/quran_reading_notifer.dart @@ -77,11 +77,11 @@ class QuranReadingNotifier extends AutoDisposeAsyncNotifier { final currentState = state.value!; if (page >= 0 && page < currentState.totalPages) { await _saveLastReadPage(page); + final targetPage = isPortairt ? page : (page / 2).floor(); if (currentState.pageController.hasClients) { - !isPortairt - ? currentState.pageController.jumpToPage((page / 2).floor()) - : currentState.pageController.jumpToPage(page); + // Calculate target page based on view mode + currentState.pageController.jumpToPage(targetPage); } final newSurahName = _getCurrentSurahName(page, currentState.suwar); From 2453d40789792138845de4c2c9d8bbd294d4f055 Mon Sep 17 00:00:00 2001 From: Ghassen Ben Zahra Date: Thu, 12 Dec 2024 00:43:14 +0100 Subject: [PATCH 05/18] remove unecssary state rotation --- .../widget/quran_floating_action_buttons.dart | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart b/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart index da0b381fb..d158f2699 100644 --- a/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart +++ b/lib/src/pages/quran/reading/widget/quran_floating_action_buttons.dart @@ -54,7 +54,6 @@ class _QuranFloatingActionControlsState extends ConsumerState { isPortrait: widget.isPortrait, icon: Icons.close, onPressed: () { - ref.read(autoScrollNotifierProvider.notifier).stopAutoScroll( - isPortairt: widget.isPortrait, - quranReadingState: widget.quranReadingState); + ref + .read(autoScrollNotifierProvider.notifier) + .stopAutoScroll(isPortairt: widget.isPortrait, quranReadingState: widget.quranReadingState); }, tooltip: 'Exit Auto-Scroll', ); @@ -333,10 +332,8 @@ class _ActionButton extends StatelessWidget { class _OrientationToggleButton extends ConsumerWidget { final FocusNode switchScreenViewFocusNode; - final int currentPage; const _OrientationToggleButton({ required this.switchScreenViewFocusNode, - required this.currentPage, }); @override @@ -363,10 +360,6 @@ class _OrientationToggleButton extends ConsumerWidget { size: iconSize, ), onPressed: () { - ref - .read(quranReadingNotifierProvider.notifier) - .updatePage(currentPage); - ref.read(quranReadingNotifierProvider.notifier).toggleRotation(); }, heroTag: null, From 6c88bc987cecd48ec861360cf311c8fe972121f5 Mon Sep 17 00:00:00 2001 From: Yassin Date: Fri, 13 Dec 2024 20:27:23 +0200 Subject: [PATCH 06/18] fix: the change in page caused by the rotation --- .../widget/reading/quran_reading_widgets.dart | 89 ++++++++++--------- .../quran/reading/quran_reading_notifer.dart | 8 ++ 2 files changed, 56 insertions(+), 41 deletions(-) diff --git a/lib/src/pages/quran/widget/reading/quran_reading_widgets.dart b/lib/src/pages/quran/widget/reading/quran_reading_widgets.dart index 17fc234cb..1223317a9 100644 --- a/lib/src/pages/quran/widget/reading/quran_reading_widgets.dart +++ b/lib/src/pages/quran/widget/reading/quran_reading_widgets.dart @@ -71,49 +71,56 @@ class HorizontalPageViewWidget extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final autoScrollState = ref.watch(autoScrollNotifierProvider); - return PageView.builder( - reverse: Directionality.of(context) == TextDirection.ltr ? true : false, - controller: quranReadingState.pageController, - onPageChanged: (index) { - final actualPage = index * 2; - if (actualPage != quranReadingState.currentPage) { - ref.read(quranReadingNotifierProvider.notifier).updatePage(actualPage); - } + final readingState = ref.watch(quranReadingNotifierProvider); + return readingState.maybeWhen( + orElse: () { + return const SizedBox.shrink(); }, - itemCount: (quranReadingState.totalPages / 2).ceil(), - itemBuilder: (context, index) { - return LayoutBuilder( - builder: (context, constraints) { - final pageWidth = constraints.maxWidth / 2; - final pageHeight = constraints.maxHeight; - final bottomPadding = pageHeight * 0.05; + data: (readingState) { + return PageView.builder( + reverse: Directionality.of(context) == TextDirection.ltr ? true : false, + controller: quranReadingState.pageController, + onPageChanged: (index) { + final actualPage = index * 2; + if (actualPage != quranReadingState.currentPage) { + ref.read(quranReadingNotifierProvider.notifier).updatePage(actualPage); + } + }, + itemCount: (quranReadingState.totalPages / 2).ceil(), + itemBuilder: (context, index) { + return LayoutBuilder( + builder: (context, constraints) { + final pageWidth = constraints.maxWidth / 2; + final pageHeight = constraints.maxHeight; + final bottomPadding = pageHeight * 0.05; - final leftPageIndex = index * 2; - final rightPageIndex = leftPageIndex + 1; - return Stack( - children: [ - if (rightPageIndex < quranReadingState.svgs.length) - Positioned( - left: 12.w, - top: 0, - bottom: bottomPadding, - width: pageWidth * 0.9, - child: SvgPictureWidget( - svgPicture: quranReadingState.svgs[rightPageIndex % quranReadingState.svgs.length], - ), - ), - if (leftPageIndex < quranReadingState.svgs.length) - Positioned( - right: 12.w, - top: 0, - bottom: bottomPadding, - width: pageWidth * 0.9, - child: SvgPictureWidget( - svgPicture: quranReadingState.svgs[leftPageIndex % quranReadingState.svgs.length], - ), - ), - ], + final leftPageIndex = index * 2; + final rightPageIndex = leftPageIndex + 1; + return Stack( + children: [ + if (rightPageIndex < quranReadingState.svgs.length) + Positioned( + left: 12.w, + top: 0, + bottom: bottomPadding, + width: pageWidth * 0.9, + child: SvgPictureWidget( + svgPicture: quranReadingState.svgs[rightPageIndex % quranReadingState.svgs.length], + ), + ), + if (leftPageIndex < quranReadingState.svgs.length) + Positioned( + right: 12.w, + top: 0, + bottom: bottomPadding, + width: pageWidth * 0.9, + child: SvgPictureWidget( + svgPicture: quranReadingState.svgs[leftPageIndex % quranReadingState.svgs.length], + ), + ), + ], + ); + }, ); }, ); diff --git a/lib/src/state_management/quran/reading/quran_reading_notifer.dart b/lib/src/state_management/quran/reading/quran_reading_notifer.dart index 3344e2878..af35b6f72 100644 --- a/lib/src/state_management/quran/reading/quran_reading_notifer.dart +++ b/lib/src/state_management/quran/reading/quran_reading_notifer.dart @@ -209,8 +209,16 @@ class QuranReadingNotifier extends AutoDisposeAsyncNotifier { Future toggleRotation() async { state = await AsyncValue.guard(() async { + final currentPage = state.value!.currentPage; + state.value!.pageController.dispose(); + return state.value!.copyWith( isRotated: !state.value!.isRotated, + pageController: PageController( + initialPage: !state.value!.isRotated ? currentPage : currentPage ~/ 2, + keepPage: true + ), + currentPage: currentPage, ); }); } From f835f58678496eba064e8e8f08c47777ca8cc1eb Mon Sep 17 00:00:00 2001 From: Yassin Date: Sat, 14 Dec 2024 14:23:12 +0200 Subject: [PATCH 07/18] fix: enlarging the font size --- .../quran/reading/quran_reading_screen.dart | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index 4f55f08df..b6c239f37 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -72,34 +72,35 @@ class AutoScrollViewStrategy implements QuranViewStrategy { return Stack( children: [ ListView.builder( - key: PageStorageKey('auto_scroll_list'), // Add key to preserve scroll position physics: NeverScrollableScrollPhysics(), controller: autoScrollState.scrollController, itemCount: state.totalPages, cacheExtent: MediaQuery.of(context).size.height * preloadDistance, // Reduce cache extent - itemExtent: MediaQuery.of(context).size.height * scalingFactor, // Use itemExtent for fixed height addRepaintBoundaries: true, // Optimize repaint boundaries itemBuilder: (context, index) { - return GestureDetector( - onTap: () { - final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); - if (autoScrollState.isPlaying) { - autoScrollNotifier.pauseAutoScroll(); - } else { - autoScrollNotifier.resumeAutoScroll(); - } - }, - child: SizedBox( - width: MediaQuery.of(context).size.width * scalingFactor, - height: MediaQuery.of(context).size.height * scalingFactor, - child: SvgPictureWidget( - svgPicture: state.svgs[index], + return RepaintBoundary( + child: GestureDetector( + onTap: () { + final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); + if (autoScrollState.isPlaying) { + autoScrollNotifier.pauseAutoScroll(); + } else { + autoScrollNotifier.resumeAutoScroll(); + } + }, + child: SizedBox( + width: MediaQuery.of(context).size.width * scalingFactor, + height: MediaQuery.of(context).size.height * scalingFactor, + child: SvgPictureWidget( + svgPicture: state.svgs[index], + ), ), ), ); }, ), - if (autoScrollState.isLoading) + + if (autoScrollState.isLoading) // Show loading screen only when isLoading is true Container( color: Colors.white.withOpacity(0.7), child: Center( From bbcf82f63c7462762cb084236366a5daf9d85b8c Mon Sep 17 00:00:00 2001 From: Yassin Date: Sat, 14 Dec 2024 16:00:19 +0200 Subject: [PATCH 08/18] fix format --- lib/src/pages/quran/reading/quran_reading_screen.dart | 1 - .../quran/reading/quran_reading_notifer.dart | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index b6c239f37..a5f4047ae 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -99,7 +99,6 @@ class AutoScrollViewStrategy implements QuranViewStrategy { ); }, ), - if (autoScrollState.isLoading) // Show loading screen only when isLoading is true Container( color: Colors.white.withOpacity(0.7), diff --git a/lib/src/state_management/quran/reading/quran_reading_notifer.dart b/lib/src/state_management/quran/reading/quran_reading_notifer.dart index af35b6f72..628b979b8 100644 --- a/lib/src/state_management/quran/reading/quran_reading_notifer.dart +++ b/lib/src/state_management/quran/reading/quran_reading_notifer.dart @@ -214,10 +214,8 @@ class QuranReadingNotifier extends AutoDisposeAsyncNotifier { return state.value!.copyWith( isRotated: !state.value!.isRotated, - pageController: PageController( - initialPage: !state.value!.isRotated ? currentPage : currentPage ~/ 2, - keepPage: true - ), + pageController: + PageController(initialPage: !state.value!.isRotated ? currentPage : currentPage ~/ 2, keepPage: true), currentPage: currentPage, ); }); From 146f1b5b39c4239fec32a6a99dc16f009cabfefc Mon Sep 17 00:00:00 2001 From: Yassin Date: Sat, 14 Dec 2024 16:22:43 +0200 Subject: [PATCH 09/18] fix: reinitialize the font or reset it again --- .../quran/reading/auto_reading/auto_reading_notifier.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index 872d7b6e7..a60cc8743 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -45,6 +45,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier { state = state.copyWith( isSinglePageView: true, isLoading: true, + fontSize: 1.0, currentPage: currentPage, // Set initial page ); From ff5fbcdd56ca5e69ae3fcd255fd8e9707a192e78 Mon Sep 17 00:00:00 2001 From: Yassin Date: Sat, 14 Dec 2024 16:34:14 +0200 Subject: [PATCH 10/18] refactor: use text instead of loading --- lib/l10n/intl_ar.arb | 6 +++--- lib/l10n/intl_en.arb | 3 ++- lib/src/pages/quran/reading/quran_reading_screen.dart | 10 +++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/l10n/intl_ar.arb b/lib/l10n/intl_ar.arb index 0b138b6a5..5a87a6641 100644 --- a/lib/l10n/intl_ar.arb +++ b/lib/l10n/intl_ar.arb @@ -397,6 +397,6 @@ }, "ishaAndFajrOnly": "فقط صلاتي الفجر و العشاء", "minutesBeforeFajrPrayer": "دقائق قبل وقت صلاة الفجر", - "minutesAfterIshaPrayer": "دقائق بعد وقت صلاة العشاء" - -} \ No newline at end of file + "minutesAfterIshaPrayer": "دقائق بعد وقت صلاة العشاء", + "initializingAutoReading": "جاري التهيئة..." +} diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index ce9bde755..43626a89c 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -412,5 +412,6 @@ }, "ishaAndFajrOnly": "Fajr and Isha prayers only", "minutesBeforeFajrPrayer": "minutes before fajr prayer time", - "minutesAfterIshaPrayer": "minutes afer isha prayer time" + "minutesAfterIshaPrayer": "minutes afer isha prayer time", + "initializingAutoReading": "Initializing in progress..." } diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index a5f4047ae..41cd221dc 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -25,6 +25,7 @@ import 'package:provider/provider.dart' as provider; import 'package:mawaqit/src/pages/quran/widget/reading/quran_reading_page_selector.dart'; import 'package:mawaqit/src/routes/routes_constant.dart'; +import 'package:sizer/sizer.dart'; abstract class QuranViewStrategy { Widget buildView(QuranReadingState state, WidgetRef ref, BuildContext context); @@ -101,10 +102,13 @@ class AutoScrollViewStrategy implements QuranViewStrategy { ), if (autoScrollState.isLoading) // Show loading screen only when isLoading is true Container( - color: Colors.white.withOpacity(0.7), + color: Colors.black.withOpacity(0.9), child: Center( - child: CircularProgressIndicator( - color: Theme.of(context).primaryColor, + child: Text( + S.of(context).initializingAutoReading, + style: Theme.of(context).textTheme.headlineMedium!.copyWith( + color: Colors.white + ), ), ), ), From f793ae4cc4d51fe8dbcfdbeeb427af78fc507127 Mon Sep 17 00:00:00 2001 From: Yassin Date: Sat, 14 Dec 2024 16:43:37 +0200 Subject: [PATCH 11/18] fix: formatting --- lib/src/pages/quran/reading/quran_reading_screen.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index 41cd221dc..e6f9f302a 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -105,10 +105,8 @@ class AutoScrollViewStrategy implements QuranViewStrategy { color: Colors.black.withOpacity(0.9), child: Center( child: Text( - S.of(context).initializingAutoReading, - style: Theme.of(context).textTheme.headlineMedium!.copyWith( - color: Colors.white - ), + S.of(context).initializingAutoReading, + style: Theme.of(context).textTheme.headlineMedium!.copyWith(color: Colors.white), ), ), ), From 9558ba989ddfafea5d67bf29c13bee024ecb767e Mon Sep 17 00:00:00 2001 From: Yassin Date: Mon, 16 Dec 2024 19:25:45 +0200 Subject: [PATCH 12/18] fix: white screen for the box --- .../quran/reading/quran_reading_screen.dart | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index e6f9f302a..25269cc6b 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -77,24 +77,21 @@ class AutoScrollViewStrategy implements QuranViewStrategy { controller: autoScrollState.scrollController, itemCount: state.totalPages, cacheExtent: MediaQuery.of(context).size.height * preloadDistance, // Reduce cache extent - addRepaintBoundaries: true, // Optimize repaint boundaries itemBuilder: (context, index) { - return RepaintBoundary( - child: GestureDetector( - onTap: () { - final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); - if (autoScrollState.isPlaying) { - autoScrollNotifier.pauseAutoScroll(); - } else { - autoScrollNotifier.resumeAutoScroll(); - } - }, - child: SizedBox( - width: MediaQuery.of(context).size.width * scalingFactor, - height: MediaQuery.of(context).size.height * scalingFactor, - child: SvgPictureWidget( - svgPicture: state.svgs[index], - ), + return GestureDetector( + onTap: () { + final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); + if (autoScrollState.isPlaying) { + autoScrollNotifier.pauseAutoScroll(); + } else { + autoScrollNotifier.resumeAutoScroll(); + } + }, + child: SizedBox( + width: MediaQuery.of(context).size.width * scalingFactor, + height: MediaQuery.of(context).size.height * scalingFactor, + child: SvgPictureWidget( + svgPicture: state.svgs[index], ), ), ); From d99d0f19506aa0f927245f4995eff5efeabb3825 Mon Sep 17 00:00:00 2001 From: Yassin Date: Mon, 16 Dec 2024 20:34:00 +0200 Subject: [PATCH 13/18] show logs in riverpod using print --- lib/src/helpers/riverpod_logger.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/helpers/riverpod_logger.dart b/lib/src/helpers/riverpod_logger.dart index 8c46bf338..eba159920 100644 --- a/lib/src/helpers/riverpod_logger.dart +++ b/lib/src/helpers/riverpod_logger.dart @@ -27,7 +27,7 @@ class RiverpodLogger extends ProviderObserver { Object? newValue, ProviderContainer container, ) { - log(''' + print(''' { "provider": "${provider.name ?? provider.runtimeType}", "newValue": "$newValue", From 6cd385b9bd9359da93c3fcfefe33a73b7c4c4166 Mon Sep 17 00:00:00 2001 From: Yassin Date: Mon, 16 Dec 2024 22:22:52 +0200 Subject: [PATCH 14/18] refactor: the `AutoScrollState` with equtable --- .../reading/auto_reading/auto_reading_state.dart | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart index 9f195d31c..b759f95e8 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart @@ -1,6 +1,7 @@ +import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; -class AutoScrollState { +class AutoScrollState extends Equatable { final bool isSinglePageView; final double autoScrollSpeed; final bool isVisible; @@ -64,4 +65,17 @@ class AutoScrollState { 'isPlaying: $isPlaying' ')'; } + + @override + List get props => [ + isSinglePageView, + autoScrollSpeed, + isVisible, + fontSize, + maxFontSize, + scrollController, + isPlaying, + isLoading, + currentPage, + ]; } From d5cd6ddda9e436869b660bd12f885d27442be553 Mon Sep 17 00:00:00 2001 From: Yassin Date: Tue, 17 Dec 2024 11:13:27 +0200 Subject: [PATCH 15/18] test another prod solution --- .../auto_reading/auto_reading_notifier.dart | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index a60cc8743..b41d18f55 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/scheduler.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:mawaqit/src/state_management/quran/reading/auto_reading/auto_reading_state.dart'; @@ -39,6 +40,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier { } } + Future startAutoScroll(int currentPage, double pageHeight) async { _autoScrollTimer?.cancel(); @@ -49,11 +51,20 @@ class AutoScrollNotifier extends AutoDisposeNotifier { currentPage: currentPage, // Set initial page ); - // Ensure the ListView is built - await Future.delayed(Duration(milliseconds: 500)); + // Wait for the next frame to ensure the ListView is built + await SchedulerBinding.instance.endOfFrame; if (scrollController.hasClients) { _initializeScrollController(currentPage, pageHeight); + } else { + // If the ScrollController still doesn't have clients, wait for the next frame + SchedulerBinding.instance.addPostFrameCallback((_) { + if (scrollController.hasClients) { + _initializeScrollController(currentPage, pageHeight); + } else { + print('ScrollController is not attached to any clients!'); + } + }); } state = state.copyWith( From 63aba74592fa322c956174c8b9b5e5bda47a4d88 Mon Sep 17 00:00:00 2001 From: Yassin Date: Tue, 17 Dec 2024 13:21:47 +0200 Subject: [PATCH 16/18] test --- lib/src/pages/quran/reading/quran_reading_screen.dart | 1 + .../quran/reading/auto_reading/auto_reading_notifier.dart | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index 25269cc6b..3936c8bcf 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -264,6 +264,7 @@ class _QuranReadingScreenState extends ConsumerState { WidgetsBinding.instance.addPostFrameCallback((_) async { ref.read(downloadQuranNotifierProvider); + ref.read(autoScrollNotifierProvider); }); } diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index b41d18f55..7c245364d 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -82,6 +82,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier { } void _startScrolling() { + print('Starting auto-scrolling...'); if (!state.isPlaying) return; const duration = Duration(milliseconds: 50); @@ -90,8 +91,10 @@ class AutoScrollNotifier extends AutoDisposeNotifier { timer.cancel(); return; } + print('Scrolling... before'); if (scrollController.hasClients) { + print('Scrolling...'); final maxScroll = scrollController.position.maxScrollExtent; final currentScroll = scrollController.offset; final delta = state.autoScrollSpeed; @@ -99,8 +102,9 @@ class AutoScrollNotifier extends AutoDisposeNotifier { if (currentScroll >= maxScroll) { stopAutoScroll(); } else { + print('Scrolling... after'); scrollController.jumpTo(currentScroll + delta); - + print('Scrolling... after 2'); // Update current page during scrolling final pageHeight = scrollController.position.viewportDimension; final newPage = _calculateCurrentPage(scrollController, pageHeight); From db4b0d30585309786b49e0964a3327adde7d30d3 Mon Sep 17 00:00:00 2001 From: Yassin Date: Thu, 19 Dec 2024 08:29:35 +0200 Subject: [PATCH 17/18] refactor: add more commit --- lib/src/pages/quran/reading/quran_reading_screen.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index 3936c8bcf..364299825 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -78,6 +78,7 @@ class AutoScrollViewStrategy implements QuranViewStrategy { itemCount: state.totalPages, cacheExtent: MediaQuery.of(context).size.height * preloadDistance, // Reduce cache extent itemBuilder: (context, index) { + print('Index: $index'); return GestureDetector( onTap: () { final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); From 8a79ab3cb7772c8b3a3a67fc8856086d4a1d12d0 Mon Sep 17 00:00:00 2001 From: Yassin Date: Thu, 19 Dec 2024 08:57:24 +0200 Subject: [PATCH 18/18] test: working on passing the controller from the widget screen --- .../quran/reading/quran_reading_screen.dart | 62 +++++++++++++++---- .../auto_reading/auto_reading_notifier.dart | 8 ++- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/lib/src/pages/quran/reading/quran_reading_screen.dart b/lib/src/pages/quran/reading/quran_reading_screen.dart index 8aca54f1a..5bb584733 100644 --- a/lib/src/pages/quran/reading/quran_reading_screen.dart +++ b/lib/src/pages/quran/reading/quran_reading_screen.dart @@ -64,6 +64,7 @@ class FocusNodes { required this.switchScreenViewFocusNode, required this.switchQuranModeNode, }); + void setupFocusTraversal({required bool isPortrait}) { if (isPortrait) { setupPortraitFocusTraversal(); @@ -255,29 +256,54 @@ class FocusNodes { } } -class AutoScrollViewStrategy implements QuranViewStrategy { +// New ConsumerStatefulWidget to manage ScrollController +class AutoScrollReadingView extends ConsumerStatefulWidget { final AutoScrollState autoScrollState; - final int preloadDistance = 3; // Adjust preload distance for performance - AutoScrollViewStrategy(this.autoScrollState); + AutoScrollReadingView({required this.autoScrollState}); @override - Widget buildView(QuranReadingState state, WidgetRef ref, BuildContext context) { - final scalingFactor = autoScrollState.fontSize; + _AutoScrollReadingViewState createState() => _AutoScrollReadingViewState(); +} + +class _AutoScrollReadingViewState extends ConsumerState { + late ScrollController scrollController; + @override + void initState() { + super.initState(); + scrollController = ScrollController(); + // Pass the ScrollController to the notifier + WidgetsBinding.instance.addPostFrameCallback((_) { + ref.read(autoScrollNotifierProvider.notifier).setScrollController(scrollController); + }); + } + + @override + void dispose() { + scrollController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final scalingFactor = widget.autoScrollState.fontSize; + final readingState = ref.watch(quranReadingNotifierProvider); + final total = readingState.whenOrNull(data: (data) => data.totalPages) ?? 0; + final pages = readingState.whenOrNull(data: (data) => data.svgs) ?? []; + final preloadDistance = 3; return Stack( children: [ ListView.builder( physics: NeverScrollableScrollPhysics(), - controller: autoScrollState.scrollController, - itemCount: state.totalPages, - cacheExtent: MediaQuery.of(context).size.height * preloadDistance, // Reduce cache extent + controller: scrollController, + itemCount: total, + cacheExtent: MediaQuery.of(context).size.height * preloadDistance, itemBuilder: (context, index) { - print('Index: $index'); return GestureDetector( onTap: () { final autoScrollNotifier = ref.read(autoScrollNotifierProvider.notifier); - if (autoScrollState.isPlaying) { + if (widget.autoScrollState.isPlaying) { autoScrollNotifier.pauseAutoScroll(); } else { autoScrollNotifier.resumeAutoScroll(); @@ -287,13 +313,13 @@ class AutoScrollViewStrategy implements QuranViewStrategy { width: MediaQuery.of(context).size.width * scalingFactor, height: MediaQuery.of(context).size.height * scalingFactor, child: SvgPictureWidget( - svgPicture: state.svgs[index], + svgPicture: pages[index], ), ), ); }, ), - if (autoScrollState.isLoading) // Show loading screen only when isLoading is true + if (widget.autoScrollState.isLoading) Container( color: Colors.black.withOpacity(0.9), child: Center( @@ -306,6 +332,18 @@ class AutoScrollViewStrategy implements QuranViewStrategy { ], ); } +} + +// Update AutoScrollViewStrategy to use AutoScrollReadingView +class AutoScrollViewStrategy implements QuranViewStrategy { + final AutoScrollState autoScrollState; + + AutoScrollViewStrategy(this.autoScrollState); + + @override + Widget buildView(QuranReadingState state, WidgetRef ref, BuildContext context) { + return AutoScrollReadingView(autoScrollState: autoScrollState); + } @override List buildControls( diff --git a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart index 7c245364d..b73cbe351 100644 --- a/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart +++ b/lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart @@ -10,7 +10,7 @@ import 'package:mawaqit/src/state_management/quran/reading/quran_reading_state.d class AutoScrollNotifier extends AutoDisposeNotifier { Timer? _autoScrollTimer; Timer? _hideTimer; - late final ScrollController scrollController; + late ScrollController scrollController; @override AutoScrollState build() { @@ -25,6 +25,12 @@ class AutoScrollNotifier extends AutoDisposeNotifier { ); } + void setScrollController(ScrollController controller) { + print('Setting scroll controller...'); + scrollController = controller; + } + + Future jumpToCurrentPage(int currentPage, double pageHeight) async { if (scrollController.hasClients) { final offset = (currentPage - 1) * pageHeight;