Untitled

 avatar
unknown
dart
3 years ago
13 kB
4
Indexable
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:iketfaa_delivery/App/Common/Modules/Dashboard/binding/dashboard_binding.dart';
import 'package:iketfaa_delivery/App/Common/Modules/Dashboard/view/dashboard_view.dart';
import 'package:iketfaa_delivery/App/Common/Modules/Language/binding/language_binding.dart';
import 'package:iketfaa_delivery/App/Common/Modules/Language/view/language_view.dart';
import 'package:iketfaa_delivery/App/Common/Modules/SupplierBankInfo/binding/supplier_bank_info_binding.dart';
import 'package:iketfaa_delivery/App/Common/Modules/SupplierBankInfo/view/supplier_bank_info_choose_national_id_view.dart';
import 'package:iketfaa_delivery/App/Common/Modules/SupplierBankInfo/view/supplier_bank_info_enter_details_view.dart';
import 'package:iketfaa_delivery/App/Common/Modules/SupplierBankInfo/view/supplier_bank_info_view.dart';
import 'package:iketfaa_delivery/App/Common/Services/AuthenticationService/Core/manager.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppColors.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/Strings/Backend.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/OrderAddress.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryHome/controller/delivery_home_controller.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/Drawer/delivery_tile_button_for_drawer.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/delivery_tile_switch_button_for_drawer.dart';

class DelvieryDrawerBodyDriver extends GetView<DeliveryHomeController> {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              'Status'.tr,
              style: Get.textTheme.headline3!.copyWith(
                fontWeight: FontWeight.normal,
              ),
            ),
            Text(
              controller.authManager.deliveryUser.value.driver == null
                  ? ''
                  : controller.authManager.deliveryTools
                      .getDeliveryDriverStatusDrawer(
                          controller
                              .authManager.deliveryUser.value.driver!.status!,
                          controller.authManager.appUser.value.provider!
                              .bankInfoAdded),
              style: Get.textTheme.bodyText1,
            ),
          ],
        ),
        Obx(
          () => DeliveryTileSwitchButtonForDrawer(
            title:
                controller.authManager.deliveryUser.value.driver!.isAvailable!
                    ? "Available".tr
                    : "Not Available".tr,
            icon: Image.asset(
              "assets/icon/map_place.png",
              height: Get.width * 0.07,
              width: Get.width * 0.07,
            ),
            trallingWidget: CupertinoSwitch(
              activeColor: AppColors.primaryDark,
              value: controller
                  .authManager.deliveryUser.value.driver!.isAvailable!,
              onChanged: (value) async {
                if (controller.authManager.deliveryUser.value.driver!.status! ==
                    1) {
                  controller.authManager.commonTools
                      .ShowWarningDialogSingleButton(
                          context,
                          'activateRequests'.tr,
                          'activateRequestsUnderReviewMessage'.tr,
                          'ok'.tr,
                          AppColors.primary, () {
                    Get.back();
                  });
                } else if (controller
                        .authManager.deliveryUser.value.driver!.status! ==
                    2) {
                  controller.authManager.commonTools
                      .ShowWarningDialogSingleButton(
                          context,
                          'activateRequests'.tr,
                          'activateRequestsRejectedMessage'.tr,
                          'ok'.tr,
                          AppColors.primary, () {
                    Get.back();
                  });
                } else if (controller
                        .authManager.deliveryUser.value.driver!.status! ==
                    3) {
                  controller.authManager.commonTools
                      .ShowWarningDialogSingleButton(
                          context,
                          'activateRequests'.tr,
                          'activateRequestsBlockedMessage'.tr,
                          'ok'.tr,
                          AppColors.primary, () {
                    Get.back();
                  });
                } else if (controller.authManager.appUser.value.provider!
                            .bankInfoAdded ==
                        false ||
                    controller.authManager.appUser.value.provider!
                            .bankInfoAdded ==
                        null) {
                  controller.authManager.commonTools
                      .ShowWarningDialogSingleButton(
                          context,
                          'activateRequests'.tr,
                          'activateRequestsNoBankInfoMessage'.tr,
                          'ok'.tr,
                          AppColors.primary, () {
                    Get.back();
                  });

                  return;
                } else {
                  print(controller
                      .authManager.deliveryUser.value.driver!.isAvailable!);
                  if (controller
                      .authManager.deliveryUser.value.driver!.isAvailable!) {
                    if (controller.authManager.deliveryUser.value.driver!
                            .activeTrip !=
                        null) {
                      return controller.authManager.commonTools
                          .ShowWarningDialogSingleButton(
                              context,
                              'failed'.tr,
                              'youAreOnActiveTripYouCannotMakeUnAvailable'.tr,
                              'ok'.tr,
                              AppColors.red, () {
                        Navigator.pop(context);
                      });
                    }
                  }

                  Map<String, dynamic> values = {};
                  if (value) {
                    values = {
                      IS_AVAILABLE_FIELD: value,
                      ADDRESS_FIELD: OrderAddress(
                        geoPoint: GeoPoint(
                          controller.authManager.appUser.value.locationData!
                              .localPosition!.latitude,
                          controller.authManager.appUser.value.locationData!
                              .localPosition!.longitude,
                        ),
                      ).toMap(),
                    };
                  } else {
                    values = {
                      IS_AVAILABLE_FIELD: value,
                    };
                  }
                  controller.authManager.commonTools.showLoading();
                  bool result = await controller
                      .deliveryHubController.updateDatabase
                      .updateDriverMultiField(values);
                  if (result) {
                    Get.back();
                  } else {
                    Get.back();
                    Get.back();
                  }
                }
              },
            ),
          ),
        ),
        Text(
          'account'.tr,
          style: Get.textTheme.headline3!.copyWith(
            fontWeight: FontWeight.normal,
          ),
        ),
        SizedBox(height: 10),
        // DelvieryTileButtonForDrawer(
        //   title: 'personal information'.tr,
        //   onTap: () async {
        //     await controller.authManager.api
        //         .updateSupplierCodeBankInfoAdded(true, null);
        //   },
        //   icon: Icon(Icons.person, color: AppColors.primary),
        // ),
        DelvieryTileButtonForDrawer(
          title: 'notification'.tr,
          onTap: () {
            controller.authManager.deliveryTools
                .openMap(31.9685027, 35.8825136);
          },
          icon: Icon(Icons.notifications, color: AppColors.primary),
        ),
        DelvieryTileButtonForDrawer(
          title: 'bank information'.tr,
          onTap: () async {
            if (controller.authManager.appUser.value.provider!.bankInfoAdded ==
                true) {
              controller.authManager.commonTools.showLoading();
              controller.authManager.appUser.value.userFirebase!.supplier =
                  await controller.authManager.firebaseCRUD.getSupplierInfo();
              Get.back();
              if (controller
                      .authManager.appUser.value.userFirebase!.supplier!.id !=
                  null)
                Get.to(() => SupplierBankInfoView(),
                    binding: SupplierBankInfoBinding());
            } else {
              if (controller.authManager.appUser.value.provider!.supplierCode ==
                  null) {
                Get.to(() => SupplierBankInfoEnterDetailsView(),
                    binding: SupplierBankInfoBinding());
              } else {
                Get.to(() => SupplierBankInfoUploadChooseNationalIdView(),
                    binding: SupplierBankInfoBinding());
              }
            }
          },
          icon: Icon(Icons.credit_card, color: AppColors.primary),
          active: controller
                      .authManager.appUser.value.provider!.bankInfoAdded ==
                  false ||
              controller.authManager.appUser.value.provider!.bankInfoAdded ==
                  null,
        ),
        DelvieryTileButtonForDrawer(
          title: 'reviews'.tr,
          onTap: () {},
          icon: Icon(Icons.favorite, color: AppColors.primary),
        ),
        DelvieryTileButtonForDrawer(
          title: 'switchToCustomer'.tr,
          onTap: () async {
            if (controller.authManager.deliveryUser.value.driver!.activeTrip !=
                null) {
              return controller.authManager.commonTools
                  .ShowWarningDialogSingleButton(
                      context,
                      'failed'.tr,
                      'youAreOnActiveTripYouCannotConvertToClient'.tr,
                      'ok'.tr,
                      AppColors.red, () {
                Navigator.pop(context);
              });
            }
            controller.authManager.commonTools.showLoading();
            bool result = await controller.deliveryHubController.updateDatabase
                .updateUserSingleField(USER_MODE_FIELD, 0);
            if (result) {
              controller.authManager.deliveryUser.update((deliveryUser) {
                deliveryUser!.userMode = 0;
              });
            }
            Get.back();
            Get.back();
          },
          icon: Icon(Icons.cached_outlined, color: AppColors.primary),
        ),
        SizedBox(height: 25.0),
        // Text(
        //   'support'.tr,
        //   style: Get.textTheme.headline3!.copyWith(
        //     fontWeight: FontWeight.normal,
        //   ),
        // ),
        // SizedBox(height: 10),
        // DelvieryTileButtonForDrawer(
        //   title: 'help'.tr,
        //   onTap: () {},
        //   icon: Icon(Icons.help_outline_outlined, color: AppColors.primary),
        // ),
        // SizedBox(height: 25.0),
        Text(
          'settings'.tr,
          style: Get.textTheme.headline3!.copyWith(
            fontWeight: FontWeight.normal,
          ),
        ),
        SizedBox(height: 10),
        DelvieryTileButtonForDrawer(
          title: 'language'.tr,
          onTap: () {
            Get.to(() => LanguageView(), binding: LanguageBinding());
          },
          icon: Icon(Icons.translate, color: AppColors.primary),
        ),
        SizedBox(height: 10),
        Divider(),
        SizedBox(height: 4),
        DelvieryTileButtonForDrawer(
          title: 'back to iktifaa'.tr,
          onTap: () {
            Get.offAll(() => DashboardView(), binding: DashboardBinding());
          },
          icon: Icon(Icons.logout, color: AppColors.primary),
        ),
        SizedBox(height: 10),
      ],
    );
  }
}
Editor is loading...