Skip to content

Commit 242d452

Browse files
code format
1 parent cf11aaf commit 242d452

File tree

3 files changed

+36
-45
lines changed

3 files changed

+36
-45
lines changed

lib/src/pages/quran/reading/quran_reading_screen.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import 'package:flutter/material.dart';
32
import 'package:flutter/rendering.dart';
43
import 'package:flutter/services.dart';
@@ -415,7 +414,6 @@ class _AutoScrollReadingViewState extends ConsumerState<AutoScrollReadingView> {
415414
return Stack(
416415
children: [
417416
Container(color: Theme.of(context).scaffoldBackgroundColor),
418-
419417
if (pages.isNotEmpty)
420418
ListView.builder(
421419
physics: NeverScrollableScrollPhysics(),
@@ -425,17 +423,14 @@ class _AutoScrollReadingViewState extends ConsumerState<AutoScrollReadingView> {
425423
itemBuilder: (context, index) {
426424
if (!_isInitialized) {
427425
return SizedBox(
428-
height: _cachedItemHeight ??
429-
MediaQuery.of(context).size.height * scalingFactor,
426+
height: _cachedItemHeight ?? MediaQuery.of(context).size.height * scalingFactor,
430427
);
431428
}
432429

433430
return _buildPage(index, pages[index], scalingFactor);
434431
},
435432
),
436-
437-
if (_isLoading || widget.autoScrollState.isLoading)
438-
_buildLoadingIndicator(),
433+
if (_isLoading || widget.autoScrollState.isLoading) _buildLoadingIndicator(),
439434
],
440435
);
441436
}
@@ -447,6 +442,7 @@ class _AutoScrollReadingViewState extends ConsumerState<AutoScrollReadingView> {
447442
super.dispose();
448443
}
449444
}
445+
450446
// Update AutoScrollViewStrategy to use AutoScrollReadingView
451447
class AutoScrollViewStrategy implements QuranViewStrategy {
452448
final AutoScrollState autoScrollState;
@@ -461,6 +457,7 @@ class AutoScrollViewStrategy implements QuranViewStrategy {
461457
initialPage: initialPage,
462458
);
463459
}
460+
464461
@override
465462
List<Widget> buildControls(
466463
BuildContext context,
@@ -754,9 +751,9 @@ class _QuranReadingScreenState extends ConsumerState<QuranReadingScreen> {
754751
// Initialize the appropriate strategy
755752
final viewStrategy = autoScrollState.isSinglePageView
756753
? AutoScrollViewStrategy(
757-
autoScrollState,
758-
initialPage: state.currentPage, // Or whatever page you want to start from
759-
)
754+
autoScrollState,
755+
initialPage: state.currentPage, // Or whatever page you want to start from
756+
)
760757
: NormalViewStrategy(isPortrait);
761758

762759
// Create focus nodes bundle

lib/src/state_management/quran/reading/auto_reading/auto_reading_notifier.dart

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class AutoScrollNotifier extends AutoDisposeNotifier<AutoScrollState> {
3131
scrollController = controller;
3232
}
3333

34-
3534
Future<void> jumpToCurrentPage(int currentPage, double pageHeight) async {
3635
if (scrollController.hasClients) {
3736
final offset = (currentPage - 1) * pageHeight;
@@ -47,8 +46,7 @@ class AutoScrollNotifier extends AutoDisposeNotifier<AutoScrollState> {
4746
}
4847
}
4948

50-
51-
Future<void> startAutoScroll(int currentPage, double pageHeight) async {
49+
Future<void> startAutoScroll(int currentPage, double pageHeight) async {
5250
// Cancel any existing timers
5351
_autoScrollTimer?.cancel();
5452
_hideTimer?.cancel();
@@ -69,15 +67,14 @@ Future<void> startAutoScroll(int currentPage, double pageHeight) async {
6967
// Robust wait for scroll controller
7068
for (int i = 0; i < 50; i++) {
7169
// 5 seconds total wait time
72-
if (scrollController.hasClients &&
73-
scrollController.position.hasContentDimensions) {
74-
_initializeScrollController(currentPage, pageHeight);
75-
break;
70+
if (scrollController.hasClients && scrollController.position.hasContentDimensions) {
71+
_initializeScrollController(currentPage, pageHeight);
72+
break;
7673
}
77-
await Future.delayed(Duration(milliseconds: 100));
78-
}
74+
await Future.delayed(Duration(milliseconds: 100));
75+
}
7976
}),
80-
77+
8178
// Additional delay to ensure view is fully rendered
8279
Future.delayed(Duration(milliseconds: 500))
8380
]);
@@ -91,7 +88,6 @@ Future<void> startAutoScroll(int currentPage, double pageHeight) async {
9188
// Start scrolling with a slight delay
9289
await Future.delayed(Duration(milliseconds: 100));
9390
_startScrolling();
94-
9591
} catch (e, stackTrace) {
9692
print('Auto-scroll initialization error: $e');
9793
print('Stacktrace: $stackTrace');
@@ -102,14 +98,15 @@ Future<void> startAutoScroll(int currentPage, double pageHeight) async {
10298
isPlaying: false,
10399
);
104100
}
105-
}
101+
}
102+
106103
void _initializeScrollController(int currentPage, double pageHeight) {
107104
final pageOffset = (currentPage - 1) * pageHeight;
108105
// Set initial offset to correct position, account for rotation if necessary
109106
scrollController.jumpTo(pageOffset);
110107
}
111108

112-
void _startScrolling() {
109+
void _startScrolling() {
113110
// Cancel any existing timer to prevent multiple timers
114111
_autoScrollTimer?.cancel();
115112

@@ -141,20 +138,18 @@ void _startScrolling() {
141138
}
142139

143140
// Comprehensive client check
144-
if (scrollController.hasClients &&
145-
scrollController.position.hasContentDimensions) {
141+
if (scrollController.hasClients && scrollController.position.hasContentDimensions) {
146142
try {
147-
final maxScroll = scrollController.position.maxScrollExtent;
148-
final currentScroll = scrollController.offset;
149-
final delta = state.autoScrollSpeed;
143+
final maxScroll = scrollController.position.maxScrollExtent;
144+
final currentScroll = scrollController.offset;
145+
final delta = state.autoScrollSpeed;
150146

151147
// Detailed logging for debugging
152-
print(
153-
'Max Scroll: $maxScroll, Current Scroll: $currentScroll, Delta: $delta');
148+
print('Max Scroll: $maxScroll, Current Scroll: $currentScroll, Delta: $delta');
154149

155-
if (currentScroll >= maxScroll) {
150+
if (currentScroll >= maxScroll) {
156151
print('Reached max scroll. Stopping auto-scroll.');
157-
stopAutoScroll();
152+
stopAutoScroll();
158153
timer.cancel();
159154
return;
160155
}
@@ -165,7 +160,7 @@ void _startScrolling() {
165160
// Page calculation
166161
final pageHeight = scrollController.position.viewportDimension;
167162
final newPage = _calculateCurrentPage(scrollController, pageHeight);
168-
163+
169164
if (newPage != state.currentPage) {
170165
state = state.copyWith(currentPage: newPage);
171166
}
@@ -178,8 +173,7 @@ void _startScrolling() {
178173
} else {
179174
print('ScrollController does not have clients or content dimensions');
180175
print('HasClients: ${scrollController.hasClients}');
181-
print(
182-
'HasContentDimensions: ${scrollController.position.hasContentDimensions}');
176+
print('HasContentDimensions: ${scrollController.position.hasContentDimensions}');
183177
}
184178
});
185179
}

lib/src/state_management/quran/reading/auto_reading/auto_reading_state.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ class AutoScrollState extends Equatable {
6868

6969
@override
7070
List<Object?> get props => [
71-
isSinglePageView,
72-
autoScrollSpeed,
73-
isVisible,
74-
fontSize,
75-
maxFontSize,
76-
scrollController,
77-
isPlaying,
78-
isLoading,
79-
currentPage,
80-
];
71+
isSinglePageView,
72+
autoScrollSpeed,
73+
isVisible,
74+
fontSize,
75+
maxFontSize,
76+
scrollController,
77+
isPlaying,
78+
isLoading,
79+
currentPage,
80+
];
8181
}

0 commit comments

Comments
 (0)