build method
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.
The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.
Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
contextusing BuildContext.dependOnInheritedWidgetOfExactType.
If a widget's build method is to depend on anything else, use a StatefulWidget instead.
See also:
- StatelessWidget, which contains the discussion on performance considerations.
Implementation
@override
Widget build(BuildContext context) {
// تحديث رابط أيقونة التطبيق إذا تم تمريره / Update app icon URL if provided
// Update app icon URL if provided
if (appIconPathForPlayAudioInBackground != null &&
appIconPathForPlayAudioInBackground!.isNotEmpty) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.mounted) {
AudioCtrl.instance
.updateAppIconUrl(appIconPathForPlayAudioInBackground!);
}
});
}
// if (isDark!) {
// QuranCtrl.instance.state.isTajweed.value = 1;
// GetStorage().write(StorageConstants().isTajweed, 1);
// }
final String deviceLocale = Localizations.localeOf(context).languageCode;
final String languageCode = appLanguageCode ?? deviceLocale;
return ScaleKitBuilder(
designWidth: 375,
designHeight: 812,
designType: DeviceType.mobile,
child: QuranLibraryTheme(
snackBarStyle: snackBarStyle ??
SnackBarStyle.defaults(isDark: isDark, context: context),
ayahLongClickStyle: ayahMenuStyle ??
AyahMenuStyle.defaults(isDark: isDark, context: context),
indexTabStyle: indexTabStyle ??
IndexTabStyle.defaults(isDark: isDark, context: context),
topBarStyle: topBarStyle ??
QuranTopBarStyle.defaults(isDark: isDark, context: context),
searchTabStyle: searchTabStyle ??
SearchTabStyle.defaults(isDark: isDark, context: context),
surahInfoStyle: surahInfoStyle ??
SurahInfoStyle.defaults(isDark: isDark, context: context),
tafsirStyle: tafsirStyle ??
TafsirStyle.defaults(isDark: isDark, context: context),
bookmarksTabStyle: bookmarksTabStyle ??
BookmarksTabStyle.defaults(isDark: isDark, context: context),
topBottomQuranStyle: topBottomQuranStyle ??
TopBottomQuranStyle.defaults(isDark: isDark, context: context),
child: GetBuilder<QuranCtrl>(
builder: (quranCtrl) {
// تهيئة خاملة لخطوط الصفحات المجاورة حول الصفحة الحالية بعد أول إطار
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!context.mounted) return;
// على الويب: لا تسرق التركيز من حقول الكتابة
if (kIsWeb) {
final pf = FocusManager.instance.primaryFocus;
final isTextFieldFocused =
pf?.context?.widget is EditableText;
if (!isTextFieldFocused) {
FocusScope.of(context)
.requestFocus(quranCtrl.state.quranPageRLFocusNode);
}
}
// } else {
// // على المنصات الأخرى أبقِ السلوك كما هو
// FocusScope.of(context)
// .requestFocus(quranCtrl.state.quranPageRLFocusNode);
// }
});
return Scaffold(
backgroundColor:
backgroundColor ?? AppColors.getBackgroundColor(isDark),
body: SafeArea(
child: Stack(
alignment: Alignment.center,
children: [
Directionality(
textDirection: TextDirection.rtl,
child: withPageView
? Focus(
focusNode: quranCtrl.state.quranPageRLFocusNode,
// على الويب، إيقاف الـ autofocus لتجنّب سرقة التركيز
autofocus: kIsWeb ? false : true,
onKeyEvent: (node, event) =>
quranCtrl.controlRLByKeyboard(node, event),
child: PageView.builder(
itemCount: 604,
controller:
quranCtrl.getPageController(context),
padEnds: false,
// شرح: اختيار نوع الفيزياء حسب إعداد التحسين QuranPagesScreen
// Explanation: Choose physics type based on optimization setting
physics: const ClampingScrollPhysics(),
// شرح: إضافة allowImplicitScrolling لتحسين الأداء
// Explanation: Adding allowImplicitScrolling for better performance
allowImplicitScrolling: true,
scrollBehavior:
const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.trackpad,
PointerDeviceKind.stylus,
PointerDeviceKind.unknown
},
),
// شرح: تقليل القص لتخفيف كلفة الرسم ما لم نحتاجه
// Explanation: Reduce clipping cost unless necessary
clipBehavior: Clip.none,
// شرح: تحسين معالجة تغيير الصفحة لتقليل التقطيع
// Explanation: Optimized page change handling to reduce stuttering
onPageChanged: (pageIndex) {
// تشغيل العمليات في الخلفية لتجنب تجميد UI
// Run operations in background to avoid UI freeze
WidgetsBinding.instance
.addPostFrameCallback((_) async {
if (!context.mounted) return;
if (onPageChanged != null) {
// لا تلمس الـ Overlay إذا كان المستخدم يدير الحدث بنفسه
onPageChanged!(pageIndex);
} else {
// إزالة الـ Overlay فقط إذا كان ظاهرًا
if (quranCtrl.state.overlayEntry !=
null) {
quranCtrl.state.overlayEntry
?.remove();
quranCtrl.state.overlayEntry = null;
}
}
quranCtrl.state.currentPageNumber.value =
pageIndex + 1;
quranCtrl.saveLastPage(pageIndex + 1);
await quranCtrl.prepareFonts(pageIndex);
});
},
pageSnapping: true,
itemBuilder: (ctx, index) {
// شرح: تحسين أداء itemBuilder لتقليل التقطيع
// Explanation: Optimize itemBuilder performance to reduce stuttering
return InkWell(
onTap: () {
if (onPagePress != null) {
onPagePress!();
} else {
quranCtrl.showControlToggle();
quranCtrl.state.overlayEntry
?.remove();
quranCtrl.state.overlayEntry = null;
}
},
hoverColor: Colors.transparent,
focusColor: Colors.transparent,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
child: RepaintBoundary(
key: ValueKey('quran_page_$index'),
child: _KeepAlive(
child: PageViewBuild(
circularProgressWidget:
circularProgressWidget,
languageCode: languageCode,
juzName: juzName,
sajdaName: sajdaName,
topTitleChild: topTitleChild,
bookmarkList: bookmarkList,
ayahSelectedFontColor:
ayahSelectedFontColor,
textColor: textColor,
ayahIconColor: ayahIconColor,
showAyahBookmarkedIcon:
showAyahBookmarkedIcon,
onAyahLongPress: onAyahLongPress,
bookmarksColor: bookmarksColor,
surahNameStyle: surahNameStyle,
bannerStyle: bannerStyle,
basmalaStyle: basmalaStyle,
onSurahBannerPress:
onSurahBannerPress,
surahNumber: surahNumber,
ayahSelectedBackgroundColor:
ayahSelectedBackgroundColor,
onPagePress: onPagePress,
isDark: isDark,
fontsName: fontsName,
ayahBookmarked: ayahBookmarked,
anotherMenuChild: anotherMenuChild,
anotherMenuChildOnTap:
anotherMenuChildOnTap,
secondMenuChild: secondMenuChild,
secondMenuChildOnTap:
secondMenuChildOnTap,
userContext: parentContext,
pageIndex: index,
quranCtrl: quranCtrl,
isFontsLocal: isFontsLocal!,
),
),
),
);
},
),
)
: PageViewBuild(
circularProgressWidget: circularProgressWidget,
languageCode: languageCode,
juzName: juzName,
sajdaName: sajdaName,
topTitleChild: topTitleChild,
bookmarkList: bookmarkList,
ayahSelectedFontColor: ayahSelectedFontColor,
textColor: textColor,
ayahIconColor: ayahIconColor,
showAyahBookmarkedIcon: showAyahBookmarkedIcon,
onAyahLongPress: onAyahLongPress,
bookmarksColor: bookmarksColor,
surahNameStyle: surahNameStyle,
bannerStyle: bannerStyle,
basmalaStyle: basmalaStyle,
onSurahBannerPress: onSurahBannerPress,
surahNumber: surahNumber,
ayahSelectedBackgroundColor:
ayahSelectedBackgroundColor,
onPagePress: onPagePress,
isDark: isDark,
fontsName: fontsName,
ayahBookmarked: ayahBookmarked,
anotherMenuChild: anotherMenuChild,
anotherMenuChildOnTap: anotherMenuChildOnTap,
secondMenuChild: secondMenuChild,
secondMenuChildOnTap: secondMenuChildOnTap,
userContext: parentContext,
pageIndex: pageIndex,
quranCtrl: quranCtrl,
isFontsLocal: isFontsLocal!,
),
),
GetBuilder<QuranCtrl>(
id: 'isShowControl',
builder: (quranCtrl) {
final visible = quranCtrl.isShowControl.value;
return RepaintBoundary(
child: IgnorePointer(
ignoring: !visible,
child: AnimatedOpacity(
opacity: visible ? 1.0 : 0.0,
duration: const Duration(milliseconds: 150),
curve: Curves.easeInOut,
child: Stack(
alignment: Alignment.center,
children: [
// السلايدر السفلي - يظهر من الأسفل للأعلى
// Bottom slider - appears from bottom to top
isShowAudioSlider!
? BottomSlider(
isVisible: visible,
onClose: () {
QuranCtrl.instance.isShowControl
.value = false;
SliderController.instance
.hideBottomContent();
},
isDark: isDark,
sliderHeight:
UiHelper.currentOrientation(
40.0, 40.0, context),
style:
ayahStyle ?? AyahAudioStyle(),
contentChild:
const SizedBox.shrink(),
child: Flexible(
child: AyahsAudioWidget(
style: ayahStyle ??
AyahAudioStyle.defaults(
isDark: isDark,
context: context),
isDark: isDark,
languageCode: languageCode,
downloadManagerStyle:
ayahDownloadManagerStyle,
),
),
)
: const SizedBox.shrink(),
kIsWeb
? JumpingPageControllerWidget(
backgroundColor: backgroundColor,
isDark: isDark,
textColor: textColor,
quranCtrl: quranCtrl,
)
: const SizedBox.shrink(),
appBar == null &&
useDefaultAppBar &&
visible
? _QuranTopBar(
languageCode,
isDark,
style:
surahStyle ?? SurahAudioStyle(),
backgroundColor: backgroundColor,
downloadFontsDialogStyle:
downloadFontsDialogStyle,
isFontsLocal: isFontsLocal,
)
: const SizedBox.shrink(),
],
),
),
),
);
},
),
],
),
),
);
},
)),
);
}