Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
8.7 kB
1
Indexable
Never
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:iketfaa_delivery/App/Common/Services/translation_service.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/DriverNewOffer.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryCustomerCurrentOrder/controller/delivery_customer_current_order_controller.dart';
import 'package:iketfaa_delivery/App/Delivery/Modules/DeliveryCustomerCurrentOrder/widget/slider.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/delivery_fading_effect_map.dart';
import 'package:iketfaa_delivery/App/Delivery/Utilities/Widgets/primary_app_bar.dart';

class DeliveryCustomerCurrentOrderMap
    extends GetView<DeliveryCustomerCurrentOrderController> {
  Widget? map;
  DeliveryCustomerCurrentOrderMap({Key? key, this.addMargin, this.map})
      : super(key: key);

  final bool? addMargin;
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      top: false,
      child: Scaffold(
        body: Stack(
          children: [
            controller.customerCurrentOrder.value.offerID != null
                ? StreamBuilder<QuerySnapshot>(
                    key: Key('DriverOffer'),
                    stream: FirebaseFirestore.instance
                        .collection(DELIVERY_NEW_OFFERS_COLLECTION)
                        .where(OFFER_ID_FIELD,
                            isEqualTo:
                                controller.customerCurrentOrder.value.offerID)
                        .limit(1)
                        .snapshots(),
                    builder: (context, offerSnapShot) {
                      if (offerSnapShot.data != null) {
                        if (offerSnapShot.data!.docs.isNotEmpty) {
                          controller.driverOffer.value = DriverOffer.fromJson(
                            offerSnapShot.data!.docs[0].data()
                                as Map<String, dynamic>,
                          );
                          if (controller.driverOffer.value.orderAddress !=
                              null) {
                            Marker driverMarker = Marker(
                                markerId: MarkerId('driverLocation'),
                                position: LatLng(
                                  controller.driverOffer.value.orderAddress!
                                      .geoPoint!.latitude,
                                  controller.driverOffer.value.orderAddress!
                                      .geoPoint!.longitude,
                                ),
                                draggable: true,
                                icon: controller
                                    .dashboardController.driverLocationMarker!);
                            controller.markers[MarkerId('driverLocation')] =
                                driverMarker;
                          }
                        }
                      }

                      return Container(
                          margin: addMargin == true
                              ? EdgeInsets.only(bottom: 280.0)
                              : EdgeInsets.only(bottom: 50),
                          child: map);
                    },
                  )
                : Container(
                    margin: addMargin == true
                        ? EdgeInsets.only(bottom: 280.0)
                        : EdgeInsets.only(bottom: 50),
                    child: map,
                  ),
            addMargin == false
                ? Positioned(
                    top: 0,
                    left: 0,
                    right: 0,
                    child: Align(
                      alignment: Alignment.topCenter,
                      child: Stack(
                        children: [
                          Container(
                            width: Get.width,
                            height: Get.height * 0.1,
                            child: CustomPaint(
                              foregroundPainter: DeliveryFadingEffectMap(),
                            ),
                          ),
                          PrimaryAppBar(
                            title: 'track my orders',
                            function: () {
                              Get.back();
                            },
                          )
                        ],
                      ),
                    ),
                  )
                : Container(),
            Align(
              alignment: Alignment.bottomRight,
              child: Container(
                margin: EdgeInsets.all(10.0),
                width: Get.width * 0.1,
                height: Get.width * 0.1,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: Colors.white,
                  boxShadow: [
                    BoxShadow(
                      color: Colors.grey,
                      blurRadius: 2.0,
                      spreadRadius: 0.5,
                      offset: Offset(
                        1.0,
                        1.0,
                      ),
                    )
                  ],
                ),
                child: new Material(
                  color: Colors.transparent,
                  child: new InkWell(
                      onTap: () {
                        controller.getCurrentLocation();
                      },
                      customBorder: CircleBorder(),
                      child: Center(
                        child: Icon(Icons.my_location),
                      )),
                ),
              ),
            ),
            controller.driverOffer.value.offerID != null
                ? Positioned(
                    bottom: 0,
                    child: addMargin == false
                        ? Container(
                            color: AppColors.white,
                            width: Get.width,
                            child: Column(
                              children: [
                                SizedBox(height: 20),
                                Text(
                                  'Estimate Time'.tr,
                                  style: Get.textTheme.headline4!.copyWith(
                                      color: AppColors.grey.withOpacity(0.5)),
                                ),
                                const SizedBox(height: 15.0),
                                Text(
                                    TranslationService().isLocaleArabic()
                                        ? controller
                                            .deliveryHubController
                                            .dashboardController
                                            .timeEstimatesDeliveryDriver
                                            .value
                                            .timeEstimateDeliveryDriver![
                                                controller.driverOffer.value
                                                    .driverEstimateTime!]
                                            .nameAR!
                                        : controller
                                            .deliveryHubController
                                            .dashboardController
                                            .timeEstimatesDeliveryDriver
                                            .value
                                            .timeEstimateDeliveryDriver![
                                                controller.driverOffer.value
                                                    .driverEstimateTime!]
                                            .nameEN!,
                                    style: Get.textTheme.headline2!
                                        .copyWith(fontSize: 22)),
                                const SizedBox(height: 20),
                                SliderLine(
                                    currentOrder:
                                        controller.customerCurrentOrder.value),
                                const SizedBox(height: 20),
                              ],
                            ),
                          )
                        : Container(),
                  )
                : SizedBox(),
          ],
        ),
      ),
    );
  }
}