Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
21 kB
1
Indexable
Never
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.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/Common/Widgets/no_items_empty.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/DriverNewOrder.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryDriverActiveOrder/controller/delivery_driver_active_order_controller.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/NewOrder/controller/delivery_new_order_controller.dart';
import 'package:flutter_svg/svg.dart';
import 'package:iketfaa_delivery/App/Common/Utilities/Constants/AppStyles.dart';
import 'package:iketfaa_delivery/App/Common/Widgets/CustomShimmerEffect.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DriverNewOrders/controller/delivery_driver_new_order_controller.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DriverNewOrders/view/delivery_driver_new_order_details.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/HeaderOrder.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/JourneyDistance.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/JourneyDistanceDirectOrder.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/OrderDetails.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/delivery_shimmer_effect.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/primary_app_bar.dart';

class DeliveryDrierNewOrderView
    extends GetView<DeliveryDriverNewOrderController> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        top: false,
        child: Scaffold(
          backgroundColor: AppColors.white,
          appBar: PrimaryAppBar(
            title: "New Orders",
            icon: "assets/svg/menu.svg",
            iconColor: AppColors.black,
            function: () => Scaffold.of(context).openDrawer(),
          ),
          body: Obx(() => controller
                      .deliveryHomeController
                      .deliveryHubController
                      .authManager
                      .deliveryUser
                      .value
                      .driver ==
                  null
              ? DelivreyShimmerEffect()
              : controller.deliveryHomeController.deliveryHubController
                      .authManager.deliveryUser.value.driver!.isAvailable!
                  ? controller
                              .deliveryHomeController
                              .deliveryHubController
                              .authManager
                              .deliveryUser
                              .value
                              .driver!
                              .activeTrip !=
                          null
                      ? Container(
                          margin: const EdgeInsets.all(10.0),
                          child: Center(
                            child: Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                SvgPicture.asset(
                                  'assets/svg/delivering.svg',
                                  width: Get.width * 0.3,
                                  color: AppColors.primary,
                                ),
                                SizedBox(
                                  height: 10.0,
                                ),
                                Text(
                                  'youHaveActiveTripYouCantRecieveOrders'.tr,
                                  style: Get.textTheme.headline5,
                                  textAlign: TextAlign.center,
                                ),
                              ],
                            ),
                          ),
                        )
                      : StreamBuilder<QuerySnapshot>(
                          stream: FirebaseFirestore.instance
                              .collection(DELIVERY_NEW_ORDERS_COLLECTION)
                              .where(OFFER_ID_FIELD, isNull: true)
                              .orderBy(DATE_FIELD, descending: true)
                              .snapshots(),
                          builder: (BuildContext context,
                              AsyncSnapshot<QuerySnapshot> snapshot) {
                            if (!snapshot.hasData) {
                              return NoItemsEmpty(
                                  icon: SvgPicture.asset(
                                    "assets/svg/c_d_orders_bnb.svg",
                                    width: 25.0,
                                    color: AppColors.primary,
                                  ),
                                  message: 'noOrdersMessage');
                            } else if (snapshot.hasError) {
                              return Container(
                                width: 0.0,
                                height: 0.0,
                              );
                            } else {
                              return !snapshot.data!.docs.isEmpty
                                  ? ListView.builder(
                                      physics: BouncingScrollPhysics(),
                                      shrinkWrap: true,
                                      itemCount: snapshot.data!.docs.length,
                                      itemBuilder: (context, index) {
                                        DocumentSnapshot doc =
                                            snapshot.data!.docs[index];
                                        DriverNewOrder newOrder =
                                            DriverNewOrder.fromJson(doc.data()
                                                as Map<String, dynamic>);

                                        return Container(
                                          margin: const EdgeInsets.all(15.0),
                                          child: Column(
                                            children: [
                                              InkWell(
                                                splashColor: Colors.transparent,
                                                highlightColor:
                                                    Colors.transparent,
                                                onTap: () {
                                                  controller.driverNewOrder
                                                      .value = newOrder;
                                                  controller.setUpAllMarkers();
                                                  Get.to(
                                                    () =>
                                                        DeliveryDriverNewOrderDetails(),
                                                  );
                                                },
                                                child: IgnorePointer(
                                                  child: Container(
                                                    width: double.infinity,
                                                    decoration: BoxDecoration(
                                                        color: Colors.white,
                                                        borderRadius:
                                                            BorderRadius.only(
                                                          topLeft:
                                                              Radius.circular(
                                                            15.0,
                                                          ),
                                                          topRight:
                                                              Radius.circular(
                                                            15.0,
                                                          ),
                                                        ),
                                                        boxShadow: [
                                                          AppStyles
                                                              .primaryShadow
                                                        ]),
                                                    child: Column(
                                                      children: [
                                                        Padding(
                                                          padding: EdgeInsets
                                                              .symmetric(
                                                                  horizontal:
                                                                      20,
                                                                  vertical: 10),
                                                          child: HeaderOrder(
                                                              userImage: controller
                                                                  .authManager
                                                                  .commonTools
                                                                  .getUserProfilePicture(
                                                                      newOrder
                                                                          .customerID!),
                                                              text:
                                                                  "${newOrder.customerName}",
                                                              rate: newOrder
                                                                  .rate
                                                                  .toString(),
                                                              timeInMinute: controller
                                                                  .authManager
                                                                  .commonTools
                                                                  .getVerboseDateTimeRepFB(
                                                                      newOrder
                                                                          .date!)),
                                                        ),
                                                        const SizedBox(
                                                            height: 10),
                                                        SizedBox(
                                                          width:
                                                              double.infinity,
                                                          child:
                                                              ListView.builder(
                                                                  shrinkWrap:
                                                                      true,
                                                                  itemCount:
                                                                      newOrder
                                                                          .orders!
                                                                          .length,
                                                                  physics:
                                                                      NeverScrollableScrollPhysics(),
                                                                  itemBuilder:
                                                                      (_, index) {
                                                                    return Column(
                                                                      children: [
                                                                        const SizedBox(
                                                                            height:
                                                                                10),
                                                                        OrderDetails(
                                                                            storeType:
                                                                                newOrder.orders![index].storeType!,
                                                                            function: () {},
                                                                            image: newOrder.orders![index].storeImageRef ?? '',
                                                                            type: newOrder.orderType!,
                                                                            storeName: newOrder.orders![index].storeName!),
                                                                        const SizedBox(
                                                                            height:
                                                                                10),
                                                                        newOrder.orderType ==
                                                                                0
                                                                            ? JourneyDistance(
                                                                                from: controller.authManager.deliveryTools.calculateDistance(newOrder.orders![index].storeLocation!.lat, newOrder.orders![index].storeLocation!.lng),
                                                                                to: controller.authManager.deliveryTools.getDistanceString(newOrder.orders![index].storeLocation!.distanceFromUser!),
                                                                                withBoxShadow: false,
                                                                                border: 0,
                                                                                backgroundColor: AppColors.lightGreyColor,
                                                                              )
                                                                            : JourneyDistanceDirectOrder(
                                                                                distance: controller.authManager.deliveryTools.calculateDistance(newOrder.customerAddress!.geoPoint!.latitude, newOrder.customerAddress!.geoPoint!.longitude),
                                                                                border: 0,
                                                                                withBoxShadow: false,
                                                                                backgroundColor: AppColors.lightGreyColor),
                                                                      ],
                                                                    );
                                                                  }),
                                                        ),
                                                      ],
                                                    ),
                                                  ),
                                                ),
                                              ),
                                            ],
                                          ),
                                        );
                                      })
                                  : NoItemsEmpty(
                                      icon: SvgPicture.asset(
                                        "assets/svg/c_d_orders_bnb.svg",
                                        width: 25.0,
                                        color: AppColors.primary,
                                      ),
                                      message: 'noOrdersMessage');
                            }
                          })
                  : Container(
                      margin: const EdgeInsets.all(10.0),
                      child: Center(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Image.asset(
                              "assets/icon/map_place.png",
                              height: Get.width * 0.12,
                              width: Get.width * 0.12,
                            ),
                            SizedBox(
                              height: 10.0,
                            ),
                            Text(
                              'yourAreNotAvailableYouCantReceiverOrders'.tr,
                              style: Get.textTheme.headline5,
                              textAlign: TextAlign.center,
                            ),
                          ],
                        ),
                      ),
                    )),
        ));
  }
}

class OrderItemsDetails extends GetView<DeliveryNewOrderController> {
  OrderItemsDetails({
    Key? key,
    required this.index,
  }) : super(key: key);

  final int index;
  @override
  Widget build(BuildContext context) {
    return Obx(
      () => Row(
        children: [
          Flexible(
            child: Container(
              padding: EdgeInsets.symmetric(vertical: 7),
              height: 55,
              child: TextField(
                onChanged: (value) {
                  controller.description[index] = value;
                  controller.orderItems[index].description = value;
                },
                keyboardType: TextInputType.text,
                maxLines: 1,
                textAlign: TextAlign.start,
                style: Get.textTheme.headline6!.copyWith(
                  color: AppColors.grey.withOpacity(0.8),
                  fontWeight: FontWeight.w600,
                ),
                decoration: InputDecoration(
                  isDense: true,
                  contentPadding:
                      EdgeInsets.only(bottom: 25, left: 5, right: 5),
                  border: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(25.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide:
                        const BorderSide(color: Colors.grey, width: 0.9),
                    borderRadius: BorderRadius.circular(25.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide:
                        const BorderSide(color: Colors.grey, width: 2.0),
                    borderRadius: BorderRadius.circular(25.0),
                  ),
                  filled: true,
                  fillColor: AppColors.white,
                  hintText: controller.description[index],
                  hintStyle: Get.textTheme.headline6!.copyWith(
                    color: AppColors.grey.withOpacity(0.8),
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ),
            ),
          ),
          IconButton(
            onPressed: () {
              controller.decreaseQuantity(index, context);
            },
            icon: Text(
              '-',
              style: Get.textTheme.headline4!.copyWith(fontSize: 28.0),
            ),
          ),
          Container(
            width: 25,
            height: 25,
            decoration:
                BoxDecoration(color: AppColors.primary, shape: BoxShape.circle),
            child: Center(
              child: Text(
                controller.quantityList[index].toString(),
                style: Get.textTheme.headline4!.copyWith(
                  color: AppColors.white,
                ),
              ),
            ),
          ),
          IconButton(
            onPressed: () {
              controller.increaseQuantity(index, context);
            },
            icon: Text(
              '+',
              style: Get.textTheme.headline4!.copyWith(fontSize: 28.0),
            ),
          ),
        ],
      ),
    );
  }
}