Untitled

mail@pastecode.io avatar
unknown
dart
a year ago
12 kB
3
Indexable
Never
class MainDrawer extends StatelessWidget {
  final AuthenticationManager authManager = Get.find();
  final isArabic = TranslationService().isLocaleArabic();

  @override
  Widget build(BuildContext context) {
    return Background(
      safeAreaBottom: false,
      safeAreaTop: false,
      child: Drawer(
        elevation: 0.0,
        backgroundColor: AppColors.white,
        child: SingleChildScrollView(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    colors: [
                      AppColors.primary.withOpacity(0.6),
                      AppColors.primary,
                    ],
                    stops: [0.0, 1.0],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                ),
                child: Column(
                  children: [
                    //    const Spacer(),
                    const SizedBox(height: 50.0),
                    Row(
                      children: [
                        Container(
                          height: Get.height * 0.08,
                          width: Get.height * 0.08,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            image: DecorationImage(
                                fit: BoxFit.cover,
                                image: CachedNetworkImageProvider(
                                  authManager.appUser.value.profilePictureUrl != null
                                      ? authManager.appUser.value.profilePictureUrl!
                                      : authManager.appUser.value.id != null
                                          ? authManager.commonTools
                                              .getUserProfilePicture(authManager.appUser.value.id!)
                                          : EMPTY_USER_IMAGE,
                                )),
                            border: Border.all(
                              color: Colors.transparent,
                              width: 1.0,
                            ),
                            boxShadow: [AppStyles.primaryShadow],
                          ),
                        ).marginOnly(),
                        const SizedBox(
                          width: 10.0,
                        ),
                        Flexible(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              FittedBox(
                                child: Text(
                                  authManager.appUser.value.name ?? '',
                                  style: Get.textTheme.headline5!.copyWith(
                                    color: AppColors.white,
                                    fontWeight: FontWeight.bold,
                                    // fontSize: Get.height * 0.02,
                                  ),
                                ),
                              ),
                              FittedBox(
                                child: Text(
                                  authManager.appUser.value.userName ?? '',
                                  style: Get.textTheme.headline5!.copyWith(
                                    color: AppColors.white,
                                    fontWeight: FontWeight.bold,
                                    // fontSize: Get.height * 0.018,
                                  ),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ).paddingAll(15),
                    const SizedBox(height: 16.0),
                  ],
                ),
              ),
              Column(
                children: [
                  const SizedBox(
                    height: 10,
                  ),
                  DrawerItem(
                    icon: 'assets/svg/news.svg',
                    title: 'News',
                    onTap: () {
                      Get.to(
                        () => NewsView(),
                        binding: NewsBinding(),
                      );
                    },
                  ),
                  DrawerItem(
                    icon: 'assets/svg/Notification1.svg',
                    title: 'notification',
                    onTap: () {
                      if (authManager.appUser.value.userCategory == GUEST_USER_CATEGORY) {
                        authManager.commonTools.guestDialog(context);
                      } else {
                        Get.to(
                          () => NotificationsView(),
                          binding: NotificationsBinding(),
                          arguments: [
                            authManager.appUser.value.id,
                          ],
                        )!
                            .then((value) => authManager.api.getNotificationsCount());
                      }
                    },
                    counter: authManager.appUser.value.notificationNewCount != null
                        ? authManager.appUser.value.notificationNewCount! > 0
                            ? authManager.appUser.value.notificationNewCount.toString()
                            : null
                        : null,
                  ),
                  DrawerItem(
                    icon: 'assets/svg/address1.svg',
                    title: 'address book',
                    onTap: () {
                      if (authManager.appUser.value.userCategory == GUEST_USER_CATEGORY) {
                        authManager.commonTools.guestDialog(context);
                      } else {
                        Get.to(
                          () => AddressBookView(),
                          binding: AddressBookBinding(),
                        );
                      }
                    },
                  ),
                  DrawerItem(
                    icon: 'assets/svg/settings1.svg',
                    title: 'Settings',
                    onTap: () {
                      if (authManager.appUser.value.userCategory == GUEST_USER_CATEGORY) {
                        authManager.commonTools.guestDialog(context);
                      } else {
                        Get.to(
                          () => SettingsView(),
                          binding: SettingsBinding(),
                        );
                      }
                    },
                  ),
                  DrawerItem(
                    icon: 'assets/svg/help.svg',
                    title: 'help',
                    onTap: () {
                      if (authManager.appUser.value.userCategory == GUEST_USER_CATEGORY) {
                        authManager.commonTools.guestDialog(context);
                      } else {
                        Get.to(
                          () => HelpView(),
                          binding: HelpBinding(),
                        );
                      }
                    },
                  ),
                  DrawerItem(
                    icon: 'assets/svg/Finance.svg',
                    title: 'Wallet',
                    onTap: () {
                      Get.to(
                        () => WalletView(withAppBar: true),
                        binding: WalletBinding(),
                      );
                    },
                  ),
                  Divider(
                    color: AppColors.grey.withOpacity(0.5),
                  ).paddingSymmetric(horizontal: 15),
                  DrawerItem(
                    icon: 'assets/svg/privacy.svg',
                    title: 'Content & Privacy Policy',
                    onTap: () {
                      Get.to(
                        () => PrivacyView(),
                        binding: PrivacyBinding(),
                      );
                    },
                  ),
                  // DrawerItem(
                  //   icon: 'assets/svg/terms.svg',
                  //   title: 'Terms & Conditions',
                  //   onTap: () {
                  //     Get.to(
                  //       () => TermsView(),
                  //       binding: TermsBinding(),
                  //     );
                  //   },
                  // ),
                  DrawerItem(
                    icon: 'assets/svg/contact.svg',
                    title: 'Contact Us',
                    onTap: () {
                      Get.to(
                        () => ContactView(),
                        binding: ContactBinding(),
                      );
                    },
                  ),
                  Divider(
                    color: AppColors.grey.withOpacity(0.5),
                  ).paddingSymmetric(horizontal: 15),
                  DrawerItem(
                    icon: authManager.appUser.value.userCategory == GUEST_USER_CATEGORY
                        ? 'assets/svg/account_bnb.svg'
                        : 'assets/svg/logout.svg',
                    title: authManager.appUser.value.userCategory == GUEST_USER_CATEGORY ? 'login' : 'logout',
                    iconColor: authManager.appUser.value.userCategory == GUEST_USER_CATEGORY
                        ? AppColors.primary
                        : null,
                    onTap: () async {
                      Get.back();
                      authManager.commonTools.showLoading();

                      Future.delayed(const Duration(milliseconds: 300), () async {
                        Get.back();
                        await authManager.logOut(true);
                      });
                    },
                  ),
                ],
              ),
              // const Spacer(
              //   flex: 4,
              // ),
            ],
          ),
        ),
      ),
    );
  }
}

class DrawerItem extends StatelessWidget {
  final String icon;
  final String title;
  final String? counter;
  final Color? iconColor;
  final Function() onTap;

  const DrawerItem(
      {Key? key, required this.icon, required this.title, required this.onTap, this.iconColor, this.counter})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: IntrinsicHeight(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              height: Get.height * 0.03,
              width: Get.height * 0.03,
              child: SvgPicture.asset(
                icon,
                color: iconColor,
              ),
            ),
            const VerticalDivider(),
            Text(
              title.tr,
              style: Get.textTheme.headline5!.copyWith(
                fontWeight: FontWeight.bold,
                // fontSize: Get.height * 0.02,
              ),
            ),
            const SizedBox(
              width: 8.0,
            ),
            counter != null
                ? Container(
                    padding: const EdgeInsets.all(6.0),
                    decoration: BoxDecoration(
                      color: AppColors.red,
                      shape: BoxShape.circle,
                    ),
                    child: Text(counter!,
                        style: Get.textTheme.subtitle2!.copyWith(
                          color: AppColors.white,
                        )),
                  )
                : const SizedBox(),
          ],
        ),
      ).marginSymmetric(horizontal: 15, vertical: 10),
      onTap: onTap,
    );
  }
}