PrimaryAppBar

mail@pastecode.io avatar
unknown
dart
2 years ago
13 kB
1
Indexable
Never
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:iketfaa_delivery/App/Common/Services/translation_service.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppColors.dart';

class PrimaryAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final VoidCallback? function;
  final String? icon;
  final Color? iconColor;
  final TextStyle? textStyle;
  final BuildContext? drawerContext;
  final bool? withFreelanceImages;
  final bool? withPopupMenu;
  final Widget? popupMenu;

  PrimaryAppBar({
    required this.title,
    this.function,
    this.icon,
    this.iconColor,
    this.textStyle,
    this.drawerContext,
    this.withFreelanceImages,
    this.withPopupMenu,
    this.popupMenu,
  });

  @override
  Size get preferredSize => Size.fromHeight(
        withFreelanceImages == true ? Get.height * 0.16 : Get.height * 0.08,
      );

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: PreferredSize(
        preferredSize: preferredSize,
        child: Container(
          width: Get.width,
          color: AppColors.white,
          // margin: const EdgeInsets.only(top: 50.0),
          child: function == null
              ? Material(
                  color: AppColors.white,
                  elevation: 2,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    // crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          IconButton(
                            onPressed: () {},
                            splashColor: Colors.transparent,
                            highlightColor: Colors.transparent,
                            icon: const Icon(
                              Icons.abc,
                              color: Colors.transparent,
                            ),
                          ),
                          withFreelanceImages == true
                              ? Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    // const Expanded(child: SizedBox()),
                                    Image.asset(
                                      'assets/img/freelance.png',
                                      height: Get.height * 0.065,
                                      // width: Get.width * 0.2,
                                    ),
                                    const SizedBox(
                                      width: 20,
                                    ),
                                    Image.asset(
                                      'assets/img/ministry.png',
                                      height: Get.height * 0.09,
                                      // width: Get.width * 0.22,
                                    ),
                                    // const Expanded(child: SizedBox()),
                                  ],
                                )
                              : Flexible(
                                  child: Center(
                                    child: Text(
                                      title.tr,
                                      style: textStyle != null
                                          ? textStyle
                                          : Get.textTheme.headline5!.copyWith(
                                              fontWeight: FontWeight.w600,
                                              fontSize: Get.height * 0.02,
                                              // height: 1.2,
                                              color: AppColors.primary,
                                            ),
                                      textScaleFactor: 1.0,
                                      overflow: TextOverflow.ellipsis,
                                      softWrap: true,
                                      maxLines: 2,
                                      textAlign: TextAlign.center,
                                    ),
                                  ),
                                ),
                          withPopupMenu == true
                              ? popupMenu!
                              : IconButton(
                                  onPressed: () {},
                                  splashColor: Colors.transparent,
                                  highlightColor: Colors.transparent,
                                  icon: const Icon(
                                    Icons.abc,
                                    color: Colors.transparent,
                                  ),
                                ),
                        ],
                      ),
                      withFreelanceImages == true
                          ? Flexible(
                              child: Center(
                                child: Text(
                                  title.tr,
                                  style: textStyle != null
                                      ? textStyle
                                      : Get.textTheme.headline5!.copyWith(
                                          fontWeight: FontWeight.w600,
                                          fontSize: Get.height * 0.02,
                                          // height: 1.2,
                                          color: AppColors.primary,
                                        ),
                                  textScaleFactor: 1.0,
                                  overflow: TextOverflow.ellipsis,
                                  softWrap: true,
                                  maxLines: 2,
                                  textAlign: TextAlign.center,
                                ),
                              ),
                            )
                          : const SizedBox()
                    ],
                  ),
                )
              : Material(
                  elevation: 2,
                  color: AppColors.white,
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          IconButton(
                            onPressed:
                                drawerContext != null ? () => Scaffold.of(drawerContext!).openDrawer() : function,
                            icon: icon != null
                                ? SvgPicture.asset(
                                    icon!,
                                    color: iconColor,
                                  )
                                : Transform.rotate(
                                    angle: TranslationService().isLocaleArabic() ? (180 * math.pi / 180) : 0,
                                    child: SvgPicture.asset(
                                      'assets/svg/icArrowBack.svg',
                                      color: AppColors.black,
                                    ),
                                  ),
                          ),
                          withFreelanceImages == true
                              ? Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  crossAxisAlignment: CrossAxisAlignment.center,
                                  children: [
                                    // const Expanded(child: SizedBox()),
                                    Image.asset(
                                      'assets/img/freelance.png',
                                      height: Get.height * 0.065,
                                      // width: Get.width * 0.2,
                                    ),
                                    const SizedBox(
                                      width: 20,
                                    ),
                                    Image.asset(
                                      'assets/img/ministry.png',
                                      height: Get.height * 0.09,
                                      // width: Get.width * 0.22,
                                    ),
                                    // const Expanded(child: SizedBox()),
                                  ],
                                )
                              : Flexible(
                                  child: Center(
                                    child: Text(
                                      title.tr,
                                      style: textStyle != null
                                          ? textStyle
                                          : Get.textTheme.headline5!.copyWith(
                                              fontWeight: FontWeight.w600,
                                              fontSize: Get.height * 0.02,
                                              // height: 1.2,
                                              color: AppColors.primary,
                                            ),
                                      textScaleFactor: 1.0,
                                      overflow: TextOverflow.ellipsis,
                                      softWrap: true,
                                      maxLines: 2,
                                      textAlign: TextAlign.center,
                                    ),
                                  ),
                                ),
                          withPopupMenu == true
                              ? PopupMenuButton(
                                  itemBuilder: (context) => [
                                    const PopupMenuItem(
                                      child: Text('First'),
                                      value: 1,
                                    ),
                                    const PopupMenuItem(
                                      child: Text('Second'),
                                      value: 2,
                                    )
                                  ],
                                )
                              : IconButton(
                                  // This is an empty IconButton to make sure the title is centered
                                  onPressed: () {},
                                  splashColor: Colors.transparent,
                                  highlightColor: Colors.transparent,
                                  icon: const Icon(
                                    Icons.abc,
                                    color: Colors.transparent,
                                  ),
                                ),
                        ],
                      ),
                      withFreelanceImages == true
                          ? Flexible(
                              child: Center(
                                child: Text(
                                  title.tr,
                                  style: textStyle != null
                                      ? textStyle
                                      : Get.textTheme.headline5!.copyWith(
                                          fontWeight: FontWeight.w600,
                                          fontSize: Get.height * 0.02,
                                          // height: 1.2,
                                          color: AppColors.primary,
                                        ),
                                  textScaleFactor: 1.0,
                                  overflow: TextOverflow.ellipsis,
                                  softWrap: true,
                                  maxLines: 2,
                                  textAlign: TextAlign.center,
                                ),
                              ),
                            )
                          : const SizedBox(),
                    ],
                  ),
                ),
        ),
      ),
    );
  }
}