buildWebHeader method

Widget buildWebHeader(
  1. BuildContext context
)

Implementation

Widget buildWebHeader(BuildContext context) {
  final cs = Theme.of(context).colorScheme;
  final isDark = Theme.of(context).brightness == Brightness.dark;
  final style = fontSizeController.appBarStyle.value;

  final bool isSolid = style == AppAppBarStyle.classicSolid;
  final bool isGlass = style == AppAppBarStyle.modernGlass;

  Color appBarBg;
  double elevation;
  Widget? flexibleSpace;
  BorderSide bottomBorder = BorderSide.none;

  Color headerTextColor;
  Color headerIconColor;

  if (isSolid) {
    final accent = fontSizeController.getEffectiveAccentColor();
    appBarBg = accent;
    elevation = fontSizeController.appBarShadow.value.elevation;
    headerTextColor = Colors.white;
    headerIconColor = Colors.white.withOpacity(0.9);
  } else if (isGlass) {
    appBarBg = Theme.of(context).scaffoldBackgroundColor.withOpacity(0.65);
    elevation = 0.0;
    headerTextColor = cs.primary;
    headerIconColor = cs.onSurface.withOpacity(0.8);
    flexibleSpace = ClipRect(
      child: BackdropFilter(
        filter: ImageFilter.blur(sigmaX: 12.0, sigmaY: 12.0),
        child: Container(color: Colors.transparent),
      ),
    );
    bottomBorder = BorderSide(
      color: isDark ? Colors.white.withOpacity(0.1) : Colors.black.withOpacity(0.08),
      width: 1.0,
    );
  } else {
    // Minimalist
    appBarBg = Theme.of(context).scaffoldBackgroundColor;
    elevation = 0.0;
    headerTextColor = cs.primary;
    headerIconColor = cs.onSurface.withOpacity(0.8);
    bottomBorder = BorderSide(
      color: isDark ? Colors.white.withOpacity(0.12) : Colors.black.withOpacity(0.08),
      width: 1.0,
    );
  }

  final List<Widget> newActionsForWeb = actions != null ? List.from(actions!) : [];

  if (Get.currentRoute != CommonRoutes.login) {
    newActionsForWeb.add(IconButton(
      icon: Builder(
        builder: (btnContext) {
          GetIt.I<DownloadUIRegistry>().downloadButtonContext = btnContext;
          return Obx(() {
            final count = GetIt.I<DownloadController>().downloadCount.value;
            final icon = Icon(Icons.file_download_outlined, color: headerIconColor);
            return count > 0
                ? Badge.count(
                    count: count,
                    backgroundColor: Colors.redAccent,
                    textColor: Colors.white,
                    child: icon)
                : icon;
          });
        },
      ),
      tooltip: 'Downloads',
      onPressed: () async {
        final controller = GetIt.I<DownloadController>();

        await controller.loadDownloadsIfNeeded(); // 🔥 SMART LOAD

        homeController.setEndDrawerContent(context, const DownloadScreen());
      },
    ));
  }

  if (Get.currentRoute != CommonRoutes.login) {
    newActionsForWeb.add(IconButton(
      icon: Obx(() {
        final count = homeController.notificationCount.value;
        final icon = Icon(CupertinoIcons.bell, color: headerIconColor);
        return count > 0
            ? Badge.count(
                count: count,
                backgroundColor: Colors.redAccent,
                textColor: Colors.white,
                child: icon)
            : icon;
      }),
      tooltip: 'Notifications',
      onPressed: () {
        homeController.setEndDrawerContent(context, NotificationView());
      },
    ));
  }

  if (Get.currentRoute != CommonRoutes.login &&
      Get.currentRoute != CommonRoutes.home) {
    newActionsForWeb.add(IconButton(
      icon: Icon(Icons.home_rounded, color: headerIconColor),
      tooltip: 'Home',
      onPressed: onHomeCallback ??
          () {
            homeController.navigateToHomeScreen();
          },
    ));
  }

  // Add All Apps icon
  if (Get.currentRoute != CommonRoutes.login) {
    newActionsForWeb.add(IconButton(
      icon: Icon(CupertinoIcons.square_grid_2x2, color: headerIconColor),
      tooltip: 'Main Menu',
      onPressed: () async {
        await homeController.loadListingIfNeeded(); // 🔥 SMART LOAD

        homeController.setEndDrawerContent(context, AllAppsDrawer());
      },
    ));
  }

  if (Get.currentRoute != CommonRoutes.login) {
    newActionsForWeb.add(buildUserProfile(context, textColor: headerTextColor, iconColor: headerIconColor));
  }

  return AppBar(
    toolbarHeight: fontSizeController.appBarHeight.value.height,
    title: Row(
            children: [
              InkWell(
                onTap: Get.currentRoute != CommonRoutes.login
                    ? onHomeCallback ??
                        () => homeController.navigateToHomeScreen()
                    : null,
                child: SizedBox(
                  height: 50.0,
                  width: 200.0,
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      AppUtils.buildClientLogo(appConfigService.getClientType()),
                      buildModuleName(context, appConfigService.getModuleType(), textColor: headerTextColor)
                    ],
                  ),
                ),
              ),
            ],
          ),
    elevation: elevation,
    backgroundColor: appBarBg,
    surfaceTintColor: Colors.transparent,
    flexibleSpace: flexibleSpace,
    shape: Border(bottom: bottomBorder),
    iconTheme: IconThemeData(color: headerIconColor),
    actionsIconTheme: IconThemeData(color: headerIconColor),
    automaticallyImplyLeading: automaticallyImplyLeading,
    actions: newActionsForWeb.isNotEmpty ? newActionsForWeb : null,
    bottom: bottom,
    centerTitle: fontSizeController.appBarTitleAlignment.value == AppAppBarTitleAlignment.center,
    leading: leading,
  );
}