build method

  1. @override
Widget build(
  1. BuildContext context
)
override

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:

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) {
  AudioCtrl.instance;
  // تحديث رابط أيقونة التطبيق إذا تم تمريره / Update app icon URL if provided
  // Update app icon URL if provided
  if (appIconUrlForPlayAudioInBackground != null &&
      appIconUrlForPlayAudioInBackground!.isNotEmpty) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      AudioCtrl.instance
          .updateAppIconUrl(appIconUrlForPlayAudioInBackground!);
    });
  }
  // شرح: تهيئة الشاشة وإعداد المقاييس
  // Explanation: Initialize screen and setup dimensions
  return ScreenUtilInit(
    designSize: const Size(392.72727272727275, 800.7272727272727),
    minTextAdapt: true,
    splitScreenMode: true,
    builder: (_, child) {
      return GetBuilder<SurahCtrl>(
        init: SurahCtrl.instance,
        initState: (state) {
          // شرح: تحميل السورة عند بناء الشاشة
          // Explanation: Load surah when building screen
          WidgetsBinding.instance.addPostFrameCallback((_) {
            final ctrl = state.controller!;
            // شرح: إعادة تحميل السورة إذا تغير رقمها
            // Explanation: Reload surah if its number changed
            AudioCtrl.instance;
            if (ctrl.surahNumber != surahNumber) {
              ctrl.loadSurah(surahNumber);
            }
          });
        },
        builder: (surahCtrl) {
          return Directionality(
            textDirection: TextDirection.rtl,
            child: Scaffold(
              backgroundColor:
                  backgroundColor ?? AppColors.getBackgroundColor(isDark),
              appBar: appBar ??
                  (useDefaultAppBar
                      ? AppBar(
                          backgroundColor: backgroundColor ??
                              AppColors.getBackgroundColor(isDark),
                          elevation: 0,
                          centerTitle: true,
                          title: Text(
                            surahCtrl.getSurahName(),
                            style: QuranLibrary().naskhStyle.copyWith(
                                  color: isDark ? Colors.white : Colors.black,
                                  fontSize: 22,
                                ),
                          ),
                          iconTheme: IconThemeData(
                            color: isDark ? Colors.white : Colors.black,
                          ),
                        )
                      : null),
              drawer: appBar == null && useDefaultAppBar
                  ? _QuranTopBar(
                      languageCode ?? 'ar',
                      isDark,
                      backgroundColor: backgroundColor,
                      topBarStyle: QuranTopBarStyle.defaults(isDark: isDark),
                    )
                  : null,
              body: SafeArea(
                  child: InkWell(
                onTap: () {
                  if (onPagePress != null) {
                    onPagePress!();
                  } else {
                    quranCtrl.showControlToggle();
                    quranCtrl.clearSelection();
                    quranCtrl.state.overlayEntry?.remove();
                    quranCtrl.state.overlayEntry = null;
                  }
                },
                focusColor: Colors.transparent,
                splashColor: Colors.transparent,
                highlightColor: Colors.transparent,
                child: Stack(
                  alignment: Alignment.center,
                  children: [
                    _buildSurahBody(parentContext, surahCtrl),

                    // السلايدر السفلي - يظهر من الأسفل للأعلى
                    // Bottom slider - appears from bottom to top
                    isShowAudioSlider!
                        ? Padding(
                            padding:
                                const EdgeInsets.symmetric(horizontal: 16.0),
                            child: Obx(() => BottomSlider(
                                  isVisible:
                                      QuranCtrl.instance.isShowControl.value,
                                  onClose: () {
                                    QuranCtrl.instance.isShowControl.value =
                                        false;
                                    SliderController.instance
                                        .hideBottomContent();
                                  },
                                  style: ayahStyle ?? AyahAudioStyle(),
                                  contentChild: SizedBox.shrink(),
                                  child: Flexible(
                                    child: AyahsAudioWidget(
                                        style: ayahStyle ?? AyahAudioStyle()),
                                  ),
                                )),
                          )
                        : SizedBox.shrink(),
                  ],
                ),
              )),
            ),
          );
        },
      );
    },
  );
}