controlRLByKeyboard method
Implementation
KeyEventResult controlRLByKeyboard(FocusNode node, KeyEvent event) {
// على الويب، التقط فقط KeyDown لتجنب التكرارات أو التعارض مع KeyUp
if (event is! KeyDownEvent) return KeyEventResult.ignored;
// تأكد من جاهزية المتحكم قبل التحريك
if (!quranPagesController.hasClients) return KeyEventResult.ignored;
// وضع الصفحتين (viewportFraction < 1): نقفز بمقدار 2
final step = quranPagesController.viewportFraction < 1.0 ? 2 : 1;
final currentIndex = quranPagesController.page?.round() ?? 0;
if (event.logicalKey == LogicalKeyboardKey.arrowLeft) {
log('Left Arrow Pressed');
final target = currentIndex + step;
if (target <= 603) {
quranPagesController.animateToPage(
target,
duration: const Duration(milliseconds: 600),
curve: Curves.easeInOut,
);
}
return KeyEventResult.handled;
} else if (event.logicalKey == LogicalKeyboardKey.arrowRight) {
log('Right Arrow Pressed');
final target = currentIndex - step;
if (target >= 0) {
quranPagesController.animateToPage(
target,
duration: const Duration(milliseconds: 600),
curve: Curves.easeInOut,
);
}
return KeyEventResult.handled;
}
return KeyEventResult.ignored;
}