import 'dart:async';
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:geolocator/geolocator.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '/models/detail_work_model.dart';
import '/screen/kurir_konfirmasi_screen/kurir_tolak_provider.dart';
import '/screen/work_process_screen/detail_work_provider.dart';
import '/screen/work_process_screen/other_deliver_person_provider.dart';
import '/screen/work_process_screen/other_delivery_location_provider.dart';
import '/screen/work_process_screen/other_receive_person_provider.dart';
import '/screen/work_process_screen/result_deliver_person_provider.dart';
import '/screen/work_process_screen/result_delivery_location_provider.dart';
import '/screen/work_process_screen/result_receive_person_provider.dart';
import '/screen/work_process_screen/sample_deliver_person_provider.dart';
import '/screen/work_process_screen/sample_delivery_location_provider.dart';
import '/screen/work_process_screen/sample_receive_person_provider.dart';
import '/widget/map_dialog.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:maps_launcher/maps_launcher.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:geocoding/geocoding.dart';

import '../../app/constant.dart';
import '../../widget/konfirmasi_kurir_dialog.dart';
import '../../widget/patient_card.dart';
import '../../widget/snackbar_widget.dart';
import 'work_input_suhu_provider.dart';
import 'work_tunda_provider.dart';

// 1	Lokasi Awal (Pengambilan)
// 2	Lokasi Akhir (Pengambilan)
// 3	Lokasi Awal (Pengantaran)
// 4	Lokasi Akhir (Pengantaran)
class DetailWorkProp {
  final int tipeId;
  final String kurirId;
  final String deliveryId;
  final String nomorLab;
  final String tujuan;
  final String catatanFo;

  DetailWorkProp(this.tipeId, this.kurirId, this.deliveryId, this.nomorLab,
      this.tujuan, this.catatanFo);
}

enum getLocationStepEnum {
  inputSuhu,
  workKonfirmasi,
  pengambilanAwal,
  pengambilanAkhir,
  catatanPengambilan,
  pengantaranAwal,
  pengantaranAkhir,
  catatanPengantaran,
  done
}

class WorkProcessScreen extends HookConsumerWidget {
  const WorkProcessScreen({super.key, required this.data});

  final DetailWorkProp data;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    print("tipe id : ${data.tipeId}");
    final detailData = useState<DetailWorkModel>(DetailWorkModel());
    final petugasPenyerahanController = useTextEditingController(text: "");
    final catatanController = useTextEditingController(text: "");
    final buttonLocation = useState(true);
    final buttonSave = useState(false);
    final petugasPenyerahanTemp = useState("");
    final pengambilanAwalLoc =
        useState<Map<String, String>>({"long": "", "lat": ""});
    final pengambilanAkhirLoc =
        useState<Map<String, String>>({"long": "", "lat": ""});
    final pengantaranAwalLoc =
        useState<Map<String, String>>({"long": "", "lat": ""});
    final pengantaranAkhirLoc =
        useState<Map<String, String>>({"long": "", "lat": ""});
    final kurirKonfirmasi = useState(false);
    final sudahAdaLokasiAwal = useState(false);
    final noteKurir = useTextEditingController(text: "");
    final petugasPengambilan = useState("");
    final petugasPengantaran = useState("");
    final catatanPengambilan = useState("");
    final catatanPengantaran = useState("");
    final getLocationStep = useState(getLocationStepEnum.pengambilanAwal);
    // final getLocationStep = useState(getLocationStepEnum.inputSuhu);
    final getLocationLoading = useState(false);
    final detailLoading = useState(false);
    final address = useState("");
    final tempLocation = useState<Map<String, String>>({"long": "", "lat": ""});

    // WORK TUNDA
    final buttonTundaShow = useState(false);
    final ctrlNoteTunda = useTextEditingController(text: "");
    final errorMessage = useState("");

    final hideInfo = useState(false);
    final showSuhuBoxBottom = useState(false);
    final showPetugasPenyerahan = useState(false);
    final showCatatan = useState(false);

    // INPUTAN INFO
    final jumlahPasienController = useTextEditingController(text: "0");
    final edtaRutinController = useTextEditingController(text: "0");
    final darahCitrasController = useTextEditingController(text: "0");
    final serumController = useTextEditingController(text: "0");
    final urineController = useTextEditingController(text: "0");
    final pleuraController = useTextEditingController(text: "0");
    final otherTextBahanController = useTextEditingController(text: "");
    final totalOtherController = useTextEditingController(text: "0");
    final suhuBoxController = useTextEditingController(text: "");
    final suhuSampleController = useTextEditingController(text: "");

    fetchData() {
      ref.read(DetailWorkProvider.notifier).getData(
          id: data.kurirId,
          tipeId: data.tipeId.toString(),
          deliveryId: data.deliveryId);
    }

    // useEffect(() {
    //   WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {

    //   });
    //   return () {};
    // }, []);
    ref.listen(DetailWorkProvider, (previous, next) {
      if (next is DetailWorkStateLoading) {
        detailLoading.value = true;
      } else if (next is DetailWorkStateError) {
        detailLoading.value = false;
        String msg = next.message;

        SanckbarWidget(context, msg, snackbarType.error);
      } else if (next is DetailWorkStateDone) {
        detailData.value = next.model;

        // print(next.model.petugasPenyerahan);
        if (data.tipeId != 5) {
          next.model.suhuBox = "0";
        }
        if (next.model.lokasiPengambilanAwal != "N") {
          kurirKonfirmasi.value = true;
        }
        if (next.model.tipeid == "1" ||
            next.model.tipeid == "2" ||
            next.model.tipeid == "3") {
          petugasPenyerahanTemp.value = next.model.petugasPenyerahan.toString();
          next.model.petugasPenyerahan = "";
        }

        if (next.model.lokasiPengambilanAwal != "N" &&
            kurirKonfirmasi.value == false) {
          sudahAdaLokasiAwal.value = true;
          kurirKonfirmasi.value = true;
          getLocationStep.value = getLocationStepEnum.pengambilanAwal;
          // getLocationStep.value = getLocationStepEnum.inputSuhu;
          print("masuk pengambilan awal awal");
        } else if (next.model.lokasiPengambilanAwal == "N" &&
            next.model.lokasiPengambilanAkhir == "N" &&
            (next.model.petugasPenyerahan == null ||
                next.model.petugasPenyerahan == "" ||
                next.model.petugasPenyerahan == "-") &&
            (next.model.notePenyerahan == null ||
                next.model.notePenyerahan == "" ||
                next.model.notePenyerahan == "-") &&
            next.model.lokasiPengantaranAwal == 'N' &&
            next.model.lokasiPengantaranAkhir == 'N' &&
            (next.model.penerima == null ||
                next.model.penerima == "" ||
                next.model.penerima == "-") &&
            (next.model.notePenerimaan == null ||
                next.model.notePenerimaan == "-" ||
                next.model.notePenerimaan == "") &&
            (next.model.suhuBox == null ||
                next.model.suhuBox == "-" ||
                next.model.suhuBox == "") &&
            (kurirKonfirmasi.value == true)) {
          // getLocationStep.value = getLocationStepEnum.inputSuhu;
          getLocationStep.value = getLocationStepEnum.pengambilanAwal;
          print("Masuk Input Suhu");
        } else if (next.model.lokasiPengambilanAwal == "N" &&
            next.model.lokasiPengambilanAkhir == "N" &&
            (next.model.petugasPenyerahan == null ||
                next.model.petugasPenyerahan == "" ||
                next.model.petugasPenyerahan == "-") &&
            (next.model.notePenyerahan == null ||
                next.model.notePenyerahan == "" ||
                next.model.notePenyerahan == "-") &&
            next.model.lokasiPengantaranAwal == 'N' &&
            next.model.lokasiPengantaranAkhir == 'N' &&
            kurirKonfirmasi.value == true &&
            (next.model.penerima == null ||
                next.model.penerima == "" ||
                next.model.penerima == "-") &&
            (next.model.notePenerimaan == null ||
                next.model.notePenerimaan == "-" ||
                next.model.notePenerimaan == "")) {
          getLocationStep.value = getLocationStepEnum.pengambilanAwal;
          // set suhu box
          suhuBoxController.text = next.model.suhuBox.toString();
          print("Masuk pengambilan awal");

          // set tunda button
          buttonTundaShow.value = false;
          print("button tunda flag ${buttonTundaShow.value}");
        } else if (next.model.lokasiPengambilanAwal == "Y" &&
            next.model.lokasiPengambilanAkhir == "N" &&
            (next.model.petugasPenyerahan == null ||
                next.model.petugasPenyerahan == "" ||
                next.model.petugasPenyerahan == "-") &&
            (next.model.notePenyerahan == null ||
                next.model.notePenyerahan == "" ||
                next.model.notePenyerahan == "-") &&
            next.model.lokasiPengantaranAwal == 'N' &&
            next.model.lokasiPengantaranAkhir == 'N' &&
            kurirKonfirmasi.value == true &&
            (next.model.penerima == null ||
                next.model.penerima == "" ||
                next.model.penerima == "-") &&
            (next.model.notePenerimaan == null ||
                next.model.notePenerimaan == "-" ||
                next.model.notePenerimaan == "")) {
          getLocationStep.value = getLocationStepEnum.pengambilanAkhir;
          pengambilanAwalLoc.value = {
            "long": next.model.lngPengambilanAwal.toString(),
            "lat": next.model.latPengambilanAwal.toString(),
          };
          // set suhu box
          suhuBoxController.text = next.model.suhuBox.toString();
          print("Masuk pengambilan akhir");
          // if (detailData.value.tipeid == "1" ||
          //     detailData.value.tipeid == "2" ||
          //     detailData.value.tipeid == "3") {
          //   petugasPenyerahanController.text =
          //       detailData.value.petugasPenyerahan ?? "";
          // }

          // set button tunda
          buttonTundaShow.value = false;
        } else if (next.model.lokasiPengambilanAwal == "Y" &&
            next.model.lokasiPengambilanAkhir == "Y" &&
            (next.model.petugasPenyerahan == null ||
                next.model.petugasPenyerahan == "" ||
                next.model.petugasPenyerahan == "-") &&
            (next.model.notePenyerahan == null ||
                next.model.notePenyerahan == "" ||
                next.model.notePenyerahan == "-") &&
            next.model.lokasiPengantaranAwal == 'N' &&
            next.model.lokasiPengantaranAkhir == 'N' &&
            kurirKonfirmasi.value == true &&
            (next.model.penerima == null ||
                next.model.penerima == "" ||
                next.model.penerima == "-") &&
            (next.model.notePenerimaan == null ||
                next.model.notePenerimaan == "-" ||
                next.model.notePenerimaan == "")) {
          pengambilanAwalLoc.value = {
            "long": next.model.lngPengambilanAwal.toString(),
            "lat": next.model.latPengambilanAwal.toString(),
          };
          pengambilanAkhirLoc.value = {
            "long": next.model.lngPengambilanAkhir.toString(),
            "lat": next.model.latPengambilanAkhir.toString(),
          };
          // set suhu box
          suhuBoxController.text = next.model.suhuBox.toString();
          print("Masuk catatan pengambilan");

          // button tunda show
          buttonTundaShow.value = true;
          buttonLocation.value = false;
          buttonSave.value = true;
          getLocationStep.value = getLocationStepEnum.catatanPengambilan;
          if (next.model.tipeid == "1" ||
              next.model.tipeid == "2" ||
              next.model.tipeid == "3") {
            petugasPenyerahanController.text = petugasPenyerahanTemp.value;
          }

          // setelah set map lokasi akhir
        } else if (next.model.lokasiPengambilanAwal == "Y" &&
            next.model.lokasiPengambilanAkhir == "Y" &&
            (next.model.petugasPenyerahan != null ||
                next.model.petugasPenyerahan != "" ||
                next.model.petugasPenyerahan != "-") &&
            (next.model.notePenyerahan != null ||
                next.model.notePenyerahan != "" ||
                next.model.notePenyerahan != "-") &&
            next.model.lokasiPengantaranAwal == 'N' &&
            next.model.lokasiPengantaranAkhir == 'N' &&
            kurirKonfirmasi.value == true &&
            (next.model.penerima == null ||
                next.model.penerima == "" ||
                next.model.penerima == "-") &&
            (next.model.notePenerimaan == null ||
                next.model.notePenerimaan == "-" ||
                next.model.notePenerimaan == "")) {
          pengambilanAwalLoc.value = {
            "long": next.model.lngPengambilanAwal.toString(),
            "lat": next.model.latPengambilanAwal.toString(),
          };
          pengambilanAkhirLoc.value = {
            "long": next.model.lngPengambilanAkhir.toString(),
            "lat": next.model.latPengambilanAkhir.toString(),
          };
          catatanPengambilan.value = next.model.notePenyerahan.toString();
          petugasPengambilan.value = next.model.petugasPenyerahan.toString();
          getLocationStep.value = getLocationStepEnum.pengantaranAwal;

          // set suhu box
          suhuBoxController.text = next.model.suhuBox.toString();

          // SET INPUTAN INFO
          jumlahPasienController.text = next.model.totalPasien.toString();
          edtaRutinController.text = next.model.totalEdta.toString();
          darahCitrasController.text = next.model.totalCitras.toString();
          serumController.text = next.model.totalSerum.toString();
          urineController.text = next.model.totalUrine.toString();
          pleuraController.text = next.model.totalPleura.toString();
          otherTextBahanController.text = next.model.otherSample.toString();
          totalOtherController.text = next.model.totalOther.toString();
          buttonTundaShow.value = true;
          print("Masuk pengantaran awal");
          buttonLocation.value = true;
          buttonSave.value = false;
        } else if (next.model.lokasiPengambilanAwal == "Y" &&
            next.model.lokasiPengambilanAkhir == "Y" &&
            (next.model.petugasPenyerahan != null ||
                next.model.petugasPenyerahan != "" ||
                next.model.petugasPenyerahan != "-") &&
            (next.model.notePenyerahan != null ||
                next.model.notePenyerahan != "" ||
                next.model.notePenyerahan != "-") &&
            next.model.lokasiPengantaranAwal == 'Y' &&
            next.model.lokasiPengantaranAkhir == 'N' &&
            kurirKonfirmasi.value == true &&
            (next.model.penerima == null ||
                next.model.penerima == "" ||
                next.model.penerima == "-") &&
            (next.model.notePenerimaan == null ||
                next.model.notePenerimaan == "-" ||
                next.model.notePenerimaan == "")) {
          buttonTundaShow.value = true;
          pengambilanAwalLoc.value = {
            "long": next.model.lngPengambilanAwal.toString(),
            "lat": next.model.latPengambilanAwal.toString(),
          };
          pengambilanAkhirLoc.value = {
            "long": next.model.lngPengambilanAkhir.toString(),
            "lat": next.model.latPengambilanAkhir.toString(),
          };
          catatanPengambilan.value = next.model.notePenyerahan.toString();
          petugasPengambilan.value = next.model.petugasPenyerahan.toString();
          pengantaranAwalLoc.value = {
            "long": next.model.lngPengantaranAwal.toString(),
            "lat": next.model.latPengantaranAwal.toString(),
          };

          // set suhu box
          suhuBoxController.text = next.model.suhuBox.toString();

          // SET INPUTAN INFO
          jumlahPasienController.text = next.model.totalPasien.toString();
          edtaRutinController.text = next.model.totalEdta.toString();
          darahCitrasController.text = next.model.totalCitras.toString();
          serumController.text = next.model.totalSerum.toString();
          urineController.text = next.model.totalUrine.toString();
          pleuraController.text = next.model.totalPleura.toString();
          otherTextBahanController.text = next.model.otherSample.toString();
          totalOtherController.text = next.model.totalOther.toString();

          print("Masuk pengantaran akhir");

          getLocationStep.value = getLocationStepEnum.pengantaranAkhir;
        } else if (next.model.lokasiPengambilanAwal == "Y" &&
            next.model.lokasiPengambilanAkhir == "Y" &&
            (next.model.petugasPenyerahan != null ||
                next.model.petugasPenyerahan != "" ||
                next.model.petugasPenyerahan != "-") &&
            (next.model.notePenyerahan != null ||
                next.model.notePenyerahan != "" ||
                next.model.notePenyerahan != "-") &&
            next.model.lokasiPengantaranAwal == 'Y' &&
            next.model.lokasiPengantaranAkhir == 'Y' &&
            kurirKonfirmasi.value == true &&
            (next.model.penerima == null ||
                next.model.penerima == "" ||
                next.model.penerima == "-") &&
            (next.model.notePenerimaan == null ||
                next.model.notePenerimaan == "-" ||
                next.model.notePenerimaan == "")) {
          pengambilanAwalLoc.value = {
            "long": next.model.lngPengambilanAwal.toString(),
            "lat": next.model.latPengambilanAwal.toString(),
          };
          pengambilanAkhirLoc.value = {
            "long": next.model.lngPengambilanAkhir.toString(),
            "lat": next.model.latPengambilanAkhir.toString(),
          };
          catatanPengambilan.value = next.model.notePenyerahan.toString();
          petugasPengambilan.value = next.model.petugasPenyerahan.toString();
          pengantaranAwalLoc.value = {
            "long": next.model.lngPengantaranAwal.toString(),
            "lat": next.model.latPengantaranAwal.toString(),
          };
          pengantaranAkhirLoc.value = {
            "long": next.model.lngPengantaranAkhir.toString(),
            "lat": next.model.latPengantaranAkhir.toString(),
          };
          getLocationStep.value = getLocationStepEnum.catatanPengantaran;
          // HIDE BAGIAN INFO
          hideInfo.value = false;

          // SHOW SUHU BOTTOM TRUE
          showSuhuBoxBottom.value = true;

          // set suhu box
          suhuBoxController.text = next.model.suhuBox.toString();
          print("Masuk catatan pengantaran ");

          buttonLocation.value = false;
          buttonSave.value = true;

          // setelah set map lokasi akhir
          buttonTundaShow.value = true;
        } else if (next.model.lokasiPengambilanAwal == "Y" &&
            next.model.lokasiPengambilanAkhir == "Y" &&
            (next.model.petugasPenyerahan != null ||
                next.model.petugasPenyerahan != "" ||
                next.model.petugasPenyerahan != "-") &&
            (next.model.notePenyerahan != null ||
                next.model.notePenyerahan != "" ||
                next.model.notePenyerahan != "-") &&
            next.model.lokasiPengantaranAwal == 'Y' &&
            next.model.lokasiPengantaranAkhir == 'Y' &&
            kurirKonfirmasi.value == true &&
            (next.model.penerima != null ||
                next.model.penerima != "" ||
                next.model.penerima != "-") &&
            (next.model.notePenerimaan != null ||
                next.model.notePenerimaan != "-" ||
                next.model.notePenerimaan != "")) {
          pengambilanAwalLoc.value = {
            "long": next.model.lngPengambilanAwal.toString(),
            "lat": next.model.latPengambilanAwal.toString(),
          };
          pengambilanAkhirLoc.value = {
            "long": next.model.lngPengambilanAkhir.toString(),
            "lat": next.model.latPengambilanAkhir.toString(),
          };
          catatanPengambilan.value = next.model.notePenyerahan.toString();
          petugasPengambilan.value = next.model.petugasPenyerahan.toString();
          pengantaranAwalLoc.value = {
            "long": next.model.lngPengantaranAwal.toString(),
            "lat": next.model.latPengantaranAwal.toString(),
          };
          pengantaranAkhirLoc.value = {
            "long": next.model.lngPengantaranAkhir.toString(),
            "lat": next.model.latPengantaranAkhir.toString(),
          };
          catatanPengantaran.value = next.model.notePenerimaan.toString();
          petugasPengantaran.value = next.model.penerima.toString();
          buttonLocation.value = false;
          buttonSave.value = false;

          // set suhu box
          suhuBoxController.text = next.model.suhuBox.toString();
          catatanPengantaran.value = next.model.notePenerimaan.toString();
          petugasPengantaran.value = next.model.penerima.toString();
          suhuSampleController.text = next.model.suhuSample.toString();
          buttonLocation.value = false;
          buttonSave.value = false;
          buttonTundaShow.value = false;
          // HIDE BAGIAN INFO
          hideInfo.value = false;
          // SHOW SUHU BOTTOM TRUE
          showSuhuBoxBottom.value = true;

          getLocationStep.value = getLocationStepEnum.done;
          print("Masuk done");
        } else {
          print("tidak masuk if else inti data");
        }

        detailLoading.value = false;
      }
    });

    // getLocationStep.addListener(
    //   () {
    //     print("step" + getLocationStep.value.toString());
    //   },
    // );

    getAddress(double lat, double long) async {
      List<Placemark> pm = await placemarkFromCoordinates(lat, long);

      // var address =
      Placemark placemark = pm[0];
      String addressD =
          "${placemark.street}, ${placemark.subLocality}, ${placemark.locality}, ${placemark.postalCode}, ${placemark.administrativeArea}";
      address.value = addressD;
      print(address.value);
    }

    Future<Position> _determinePosition(context) async {
      bool serviceEnabled;
      LocationPermission permission;
      try {
        // Test if location services are enabled.
        serviceEnabled = await Geolocator.isLocationServiceEnabled();
        if (!serviceEnabled) {
          permission = await Geolocator.requestPermission();
        }

        permission = await Geolocator.checkPermission();
        if (permission == LocationPermission.denied) {
          permission = await Geolocator.requestPermission();
          if (permission == LocationPermission.denied) {
            // Permissions are denied, next time you could try
            // requesting permissions again (this is also where
            // Android's shouldShowRequestPermissionRationale
            // returned true. According to Android guidelines
            // your App should show an explanatory UI now.
            permission = await Geolocator.requestPermission();
          }
        }

        if (permission == LocationPermission.deniedForever) {
          // Permissions are denied forever, handle appropriately.
          permission = await Geolocator.requestPermission();
        }

        // When we reach here, permissions are granted and we can
        // continue accessing the position of the device.
        // print(
        getLocationLoading.value = true;
        Position p = await Geolocator.getCurrentPosition(
            desiredAccuracy: LocationAccuracy.high);
        await getAddress(p.latitude, p.longitude);
        // print(
        //     "Current location Latitude :${p.latitude} & Longitude ${p.longitude}");
        getLocationLoading.value = false;
        return p;
      } catch (e) {
        print(e);
        getLocationLoading.value = false;
        return Position(
            altitudeAccuracy: 0,
            headingAccuracy: 0,
            longitude: 0,
            latitude: 0,
            timestamp: DateTime.now(),
            accuracy: 0,
            altitude: 0,
            heading: 0,
            speed: 0,
            speedAccuracy: 0);
      }
    }

    getLocationStep.addListener(() {
      print(getLocationStep.value);
    });

    getLocation(context) async {
      if (getLocationStep.value == getLocationStepEnum.pengambilanAwal) {
        Position p = await _determinePosition(context);
        if (p.latitude != 0 && p.longitude != 0) {
          confirm() async {
            tempLocation.value = {
              "long": p.longitude.toString(),
              "lat": p.latitude.toString()
            };
            // pengambilanAwalLoc.value = {
            //   "long": p.longitude.toString(),
            //   "lat": p.latitude.toString()
            // };
            if (data.tipeId == 5) {
              if (suhuBoxController.text.isEmpty) {
                SanckbarWidget(context, "Input Suhu Box Terlebih Dahulu",
                    snackbarType.warning);
                return;
              } else {
                ref.read(SampleDeliveryLocationProvider.notifier).setData(
                    id: data.deliveryId.toString(),
                    step: "1",
                    lat: p.latitude.toString(),
                    long: p.longitude.toString(),
                    address: address.value,
                    branchID: detailData.value.branchID!);
              }
            } else if (data.tipeId == 4) {
              ref.read(OtherDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "1",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            } else {
              ref.read(ResultDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "1",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            }
            // if (pengambilanAwalLoc.value["lat"] != "" ||
            //     pengambilanAwalLoc.value['long'] != "") {
            //   getLocationStep.value = getLocationStepEnum.pengambilanAkhir;
            // }
            Navigator.pop(context);
            // SanckbarWidget(context, "Lokasi pengambilan awal berhasil disimpan",
            //     snackbarType.success);
            // print(
            //     "Pengambilan awal Latitude :${p.latitude} & Longitude ${p.longitude}");
          }

          notConfirm() {
            getLocation(context);
          }

          showMapDialog(
              context: context,
              lat: p.latitude,
              long: p.longitude,
              address: address.value,
              confirm: confirm,
              notConfirm: notConfirm);
        }
      } else if (getLocationStep.value ==
          getLocationStepEnum.pengambilanAkhir) {
        Position p = await _determinePosition(context);
        confirm() async {
          if (p.latitude != 0 && p.longitude != 0) {
            if (data.tipeId == 5) {
              ref.read(SampleDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "2",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            } else if (data.tipeId == 4) {
              ref.read(OtherDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "2",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            } else {
              ref.read(ResultDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "2",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            }
            tempLocation.value = {
              "long": p.longitude.toString(),
              "lat": p.latitude.toString()
            };
            // pengambilanAkhirLoc.value = {
            //   "long": p.longitude.toString(),
            //   "lat": p.latitude.toString()
            // };
          }

          // if (pengambilanAkhirLoc.value["lat"] != "" ||
          //     pengambilanAkhirLoc.value['long'] != "") {
          //   // getAddress(p.latitude, p.longitude);
          //   getLocationStep.value = getLocationStepEnum.catatanPengambilan;
          //   buttonLocation.value = false;
          //   buttonSave.value = true;
          // }
          Navigator.pop(context);
          // SanckbarWidget(context, "Lokasi pengambilan akhir berhasil disimpan",
          //     snackbarType.success);
          // print(
          //     "Pengambilan akhir Latitude :${p.latitude} & Longitude ${p.longitude}");
        }

        notConfirm() {
          getLocation(context);
        }

        showMapDialog(
            context: context,
            lat: p.latitude,
            long: p.longitude,
            address: address.value,
            confirm: confirm,
            notConfirm: notConfirm);
      } else if (getLocationStep.value == getLocationStepEnum.pengantaranAwal) {
        Position p = await _determinePosition(context);
        notConfirm() {
          getLocation(context);
        }

        confirm() async {
          if (p.latitude != 0 && p.longitude != 0) {
            if (data.tipeId == 5) {
              ref.read(SampleDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "3",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            } else if (data.tipeId == 4) {
              ref.read(OtherDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "3",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            } else {
              ref.read(ResultDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "3",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            }
            tempLocation.value = {
              "long": p.longitude.toString(),
              "lat": p.latitude.toString()
            };
            // pengantaranAwalLoc.value = {
            //   "long": p.longitude.toString(),
            //   "lat": p.latitude.toString()
            // };
          }
          // if (pengantaranAwalLoc.value["lat"] != "" ||
          //     pengantaranAwalLoc.value['long'] != "") {
          //   getLocationStep.value = getLocationStepEnum.pengantaranAkhir;
          // }
          // // getAddress(p.latitude, p.longitude);
          Navigator.pop(context);
          // SanckbarWidget(context, "Lokasi pengantaran awal berhasil disimpan",
          //     snackbarType.success);
          // print(
          //     "pengantaran awal Latitude :${p.latitude} & Longitude ${p.longitude}");
        }

        showMapDialog(
            context: context,
            lat: p.latitude,
            long: p.longitude,
            address: address.value,
            confirm: confirm,
            notConfirm: notConfirm);
      } else if (getLocationStep.value ==
          getLocationStepEnum.pengantaranAkhir) {
        Position p = await _determinePosition(context);
        notConfirm() {
          getLocation(context);
        }

        confirm() async {
          if (p.latitude != 0 && p.longitude != 0) {
            if (data.tipeId == 5) {
              ref.read(SampleDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "4",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            } else if (data.tipeId == 4) {
              ref.read(OtherDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "4",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            } else {
              ref.read(ResultDeliveryLocationProvider.notifier).setData(
                  id: data.deliveryId.toString(),
                  step: "4",
                  lat: p.latitude.toString(),
                  long: p.longitude.toString(),
                  address: address.value,
                  branchID: detailData.value.branchID!);
            }
            tempLocation.value = {
              "long": p.longitude.toString(),
              "lat": p.latitude.toString()
            };
            // pengantaranAkhirLoc.value = {
            //   "long": p.longitude.toString(),
            //   "lat": p.latitude.toString()
            // };
          }

          //   if (pengantaranAkhirLoc.value["lat"] != "" ||
          //       pengantaranAkhirLoc.value['long'] != "") {
          //     getLocationStep.value = getLocationStepEnum.catatanPengantaran;
          //     buttonLocation.value = false;
          //     buttonSave.value = true;
          //   }
          //   // getAddress(p.latitude, p.longitude);
          Navigator.pop(context);
          //   SanckbarWidget(context, "Lokasi pengantaran akhir berhasil disimpan",
          //       snackbarType.success);
          //   print(
          //       "Pengantaran akhir Latitude :${p.latitude} & Longitude ${p.longitude}");
        }

        showMapDialog(
            context: context,
            lat: p.latitude,
            long: p.longitude,
            address: address.value,
            confirm: confirm,
            notConfirm: notConfirm);
      }
    }

    saveCatatan() {
      if (getLocationStep.value == getLocationStepEnum.catatanPengambilan) {
        if (data.tipeId == 5) {
          ref.read(SampleDeliverPersonProvider.notifier).setData(
                id: data.deliveryId,
                name: petugasPenyerahanController.text,
                note: catatanController.text,
                // INPUTAN INFO
                jumlahPasien: jumlahPasienController.text,
                edtaRutin: edtaRutinController.text,
                darahCitras: darahCitrasController.text,
                serum: serumController.text,
                urine: urineController.text,
                pleura: pleuraController.text,
                otherTextBahan: otherTextBahanController.text,
                totalOther: totalOtherController.text,
              );
          if (data.tipeId == 5) {
            showPetugasPenyerahan.value = false;
            showCatatan.value = false;
          }
        } else if (data.tipeId == 4) {
          ref.read(OtherDeliverPersonProvider.notifier).setData(
              id: data.deliveryId,
              name: petugasPenyerahanController.text,
              note: catatanController.text);
        } else {
          ref.read(ResultDeliverPersonProvider.notifier).setData(
              id: data.deliveryId,
              name: petugasPenyerahanController.text,
              note: catatanController.text);
        }
      } else if (getLocationStep.value ==
          getLocationStepEnum.catatanPengantaran) {
        if (data.tipeId == 5) {
          // ADD SUHU SAMPLE BOTTOM
          if (suhuSampleController.text.isEmpty) {
            SanckbarWidget(context, "Suhu Box Sample Silahkan Diisi",
                snackbarType.warning);
            return;
          } else {
            ref.read(SampleReceivePersonProvider.notifier).setData(
                  id: data.deliveryId,
                  name: petugasPenyerahanController.text,
                  note: catatanController.text,
                  suhuSample: suhuSampleController.text,
                );

            if (data.tipeId == 5) {
              showPetugasPenyerahan.value = false;
              showCatatan.value = false;
            }
          }
        } else if (data.tipeId == 4) {
          ref.read(OtherReceivePersonProvider.notifier).setData(
              id: data.deliveryId,
              name: petugasPenyerahanController.text,
              note: catatanController.text);
        } else {
          ref.read(ResultReceivePersonProvider.notifier).setData(
              id: data.deliveryId,
              name: petugasPenyerahanController.text,
              note: catatanController.text);
        }
      }
    }

    setCatatanToState() {
      if (getLocationStep.value == getLocationStepEnum.catatanPengambilan) {
        // button tunda show
        buttonTundaShow.value = true;
        catatanPengambilan.value = catatanController.text;
        petugasPengambilan.value = petugasPenyerahanController.text;
        getLocationStep.value = getLocationStepEnum.pengantaranAwal;
        buttonLocation.value = true;
        buttonSave.value = false;
        catatanController.value = TextEditingValue.empty;
        petugasPenyerahanController.text = "";
        if (detailData.value.tipeid == "1" ||
            detailData.value.tipeid == "2" ||
            detailData.value.tipeid == "3") {
          petugasPenyerahanController.text = petugasPenyerahanTemp.value;
        }
        SanckbarWidget(context, "Data berhasil disimpan", snackbarType.success);
      } else if (getLocationStep.value ==
          getLocationStepEnum.catatanPengantaran) {
        // button tunda show
        buttonLocation.value = false;
        buttonSave.value = false;
        catatanPengantaran.value = catatanController.text;
        petugasPengantaran.value = petugasPenyerahanController.text;
        getLocationStep.value = getLocationStepEnum.done;
        SanckbarWidget(context, "Data berhasil disimpan", snackbarType.success);
        // if (detailData.value.tipeid == "1" ||
        //     detailData.value.tipeid == "2" ||
        //     detailData.value.tipeid == "3") {
        //   petugasPenyerahanController.text = petugasPenyerahanTemp.value;
        // }
        buttonTundaShow.value = false;
      }
    }

    setLocationToState() {
      if (getLocationStep.value == getLocationStepEnum.pengambilanAwal) {
        pengambilanAwalLoc.value = {
          "long": tempLocation.value['long'].toString(),
          "lat": tempLocation.value['lat'].toString()
        };

        getLocationStep.value = getLocationStepEnum.pengambilanAkhir;

        // Navigator.pop(context);
        SanckbarWidget(context, "Lokasi pengambilan awal berhasil disimpan",
            snackbarType.success);
        print(
            "Pengambilan awal Latitude :${tempLocation.value['lat']} & Longitude ${tempLocation.value['long']}");
      } else if (getLocationStep.value ==
          getLocationStepEnum.pengambilanAkhir) {
        pengambilanAkhirLoc.value = {
          "long": tempLocation.value['long'].toString(),
          "lat": tempLocation.value['lat'].toString()
        };

        getLocationStep.value = getLocationStepEnum.catatanPengambilan;
        buttonLocation.value = false;
        buttonSave.value = true;

        // hanya pengambilan bahan
        if (data.tipeId == 5) {
          showPetugasPenyerahan.value = true;
          showCatatan.value = true;
          // set button tunda show
          buttonTundaShow.value = true;
        }

        // setelah set map lokasi akhir
        buttonTundaShow.value = true;

        if (detailData.value.tipeid == "1" ||
            detailData.value.tipeid == "2" ||
            detailData.value.tipeid == "3") {
          petugasPenyerahanController.text = petugasPenyerahanTemp.value;
        }

        // Navigator.pop(context);
        SanckbarWidget(context, "Lokasi pengambilan akhir berhasil disimpan",
            snackbarType.success);
        print(
            "Pengambilan akhir Latitude :${tempLocation.value['lat']} & Longitude ${tempLocation.value['long']}");
      } else if (getLocationStep.value == getLocationStepEnum.pengantaranAwal) {
        pengantaranAwalLoc.value = {
          "long": tempLocation.value['long'].toString(),
          "lat": tempLocation.value['lat'].toString()
        };
        getLocationStep.value = getLocationStepEnum.pengantaranAkhir;
        // getAddress(p.latitude, p.longitude);
        // Navigator.pop(context);
        SanckbarWidget(context, "Lokasi pengantaran awal berhasil disimpan",
            snackbarType.success);
        print(
            "pengantaran awal Latitude :${tempLocation.value['lat']} & Longitude ${tempLocation.value['long']}");
      } else if (getLocationStep.value ==
          getLocationStepEnum.pengantaranAkhir) {
        pengantaranAkhirLoc.value = {
          "long": tempLocation.value['long'].toString(),
          "lat": tempLocation.value['lat'].toString()
        };
        petugasPenyerahanController.text = "";
        getLocationStep.value = getLocationStepEnum.catatanPengantaran;
        buttonLocation.value = false;
        buttonSave.value = true;

        // hanya pengambilan bahan
        if (data.tipeId == 5) {
          // HIDE BAGIAN INFO
          hideInfo.value = false;

          // SHOW SUHU BOTTOM TRUE
          showSuhuBoxBottom.value = true;

          showPetugasPenyerahan.value = true;
          showCatatan.value = true;
        }

        // setelah set map lokasi akhir
        // buttonTundaShow.value = true;

        // getAddress(p.latitude, p.longitude);
        // Navigator.pop(context);
        SanckbarWidget(context, "Lokasi pengantaran akhir berhasil disimpan",
            snackbarType.success);
        print(
            "Pengantaran akhir Latitude :${tempLocation.value['lat']} & Longitude ${tempLocation.value['long']}");
      }
    }

    ref.listen(kurirTolakProvider, (previus, next) {
      if (next is KurirTolakStateLoading) {
        kurirKonfirmasi.value = true;
      } else if (next is KurirTolakStateError) {
        print(next.message);
        Navigator.pop(context);
        SanckbarWidget(context, next.message, snackbarType.error);
        kurirKonfirmasi.value = false;
      } else if (next is KurirTolakStateDone) {
        Navigator.of(context).pop();
        SanckbarWidget(context, "Konfirmasi pekerjaan berhasil di tolak",
            snackbarType.success);
        kurirKonfirmasi.value = false;
      }
    });
    ref.listen(ResultDeliveryLocationProvider, (previous, next) {
      if (next is ResultDeliveryLocationStateLoading) {
        getLocationLoading.value = true;
      } else if (next is ResultDeliveryLocationStateError) {
        print(next.message);
        Navigator.pop(context);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is ResultDeliveryLocationStateDone) {
        setLocationToState();

        getLocationLoading.value = false;
      }
    });
    ref.listen(SampleDeliveryLocationProvider, (previous, next) {
      if (next is SampleDeliveryLocationStateLoading) {
        getLocationLoading.value = true;
      } else if (next is SampleDeliveryLocationStateError) {
        print(next.message);
        Navigator.pop(context);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is SampleDeliveryLocationStateDone) {
        // print(jsonEncode(next.model));
        setLocationToState();
        getLocationLoading.value = false;
      }
    });
    ref.listen(OtherDeliveryLocationProvider, (previous, next) {
      if (next is OtherDeliveryLocationStateLoading) {
        getLocationLoading.value = true;
      } else if (next is OtherDeliveryLocationStateError) {
        print(next.message);
        Navigator.pop(context);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is OtherDeliveryLocationStateDone) {
        // print(next.model);
        setLocationToState();
        getLocationLoading.value = false;
      }
    });
    ref.listen(ResultDeliverPersonProvider, (previous, next) {
      if (next is ResultDeliverPersonStateLoading) {
        getLocationLoading.value = true;
      } else if (next is ResultDeliverPersonStateError) {
        print(next.message);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is ResultDeliverPersonStateDone) {
        // print(jsonEncode(next.model));
        setCatatanToState();
        if (detailData.value.tipeid == "1" ||
            detailData.value.tipeid == "2" ||
            detailData.value.tipeid == "3") {
          petugasPenyerahanController.text = petugasPenyerahanTemp.value;
        }
        getLocationLoading.value = false;
      }
    });
    ref.listen(SampleDeliverPersonProvider, (previous, next) {
      if (next is SampleDeliverPersonStateLoading) {
        getLocationLoading.value = true;
      } else if (next is SampleDeliverPersonStateError) {
        print(next.message);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is SampleDeliverPersonStateDone) {
        // print(jsonEncode(next.model));
        setCatatanToState();
        getLocationLoading.value = false;
      }
    });
    ref.listen(OtherDeliverPersonProvider, (previous, next) {
      if (next is OtherDeliverPersonStateLoading) {
        getLocationLoading.value = true;
      } else if (next is OtherDeliverPersonStateError) {
        print(next.message);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is OtherDeliverPersonStateDone) {
        // print(jsonEncode(next.model));
        setCatatanToState();
        getLocationLoading.value = false;
      }
    });
    ref.listen(ResultReceivePersonProvider, (previous, next) {
      if (next is ResultReceivePersonStateLoading) {
        getLocationLoading.value = true;
      } else if (next is ResultReceivePersonStateError) {
        print(next.message);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is ResultReceivePersonStateDone) {
        // print(jsonEncode(next.model));
        setCatatanToState();
        getLocationLoading.value = false;
      }
    });
    ref.listen(SampleReceivePersonProvider, (previous, next) {
      if (next is SampleReceivePersonStateLoading) {
        getLocationLoading.value = true;
      } else if (next is SampleReceivePersonStateError) {
        print(next.message);
        getLocationLoading.value = false;
        SanckbarWidget(context, next.message, snackbarType.error);
      } else if (next is SampleReceivePersonStateDone) {
        // print(jsonEncode(next.model));
        setCatatanToState();
        getLocationLoading.value = false;
      }
    });
    ref.listen(OtherReceivePersonProvider, (previous, next) {
      if (next is OtherReceivePersonStateLoading) {
        getLocationLoading.value = true;
      } else if (next is OtherReceivePersonStateError) {
        print(next.message);
        SanckbarWidget(context, next.message, snackbarType.error);
        getLocationLoading.value = false;
      } else if (next is OtherReceivePersonStateDone) {
        // print(jsonEncode(next.model));
        setCatatanToState();
        getLocationLoading.value = false;
      }
    });

    void requestLocationPermission() async {
      LocationPermission permission = await Geolocator.checkPermission();
      if (permission == LocationPermission.denied) {
        permission = await Geolocator.requestPermission();
        if (permission == LocationPermission.denied ||
            permission == LocationPermission.unableToDetermine) {
          permission = await Geolocator.requestPermission();
        }
        if (permission == LocationPermission.deniedForever) {
          // ignore: use_build_context_synchronously
          return showDialog<void>(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                content: const SingleChildScrollView(
                    child: Text("Untuk melanjutkan,  aktifkan lokasi Anda")),
                actions: <Widget>[
                  TextButton(
                    child: const Text('Buka pengaturan'),
                    onPressed: () async {
                      await openAppSettings();
                    },
                  ),
                ],
                shape: const RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(24))),
              );
            },
          );
        }
      }
      // Izin lokasi diberikan oleh pengguna
    }

    // SUHU PROVIDER AND FUNCTION START
    saveWorkInputSuhu(String value) {
      if (suhuBoxController.text.isEmpty) {
        SanckbarWidget(context, "Suhu Harus Di input", snackbarType.warning);
      } else {
        final param = {
          "id": data.deliveryId.toString(),
          "suhu": suhuBoxController.text,
        };

        print("param : $param");

        ref.read(workInputSuhuSave.notifier).workInputSuhu(
              deliveryId: data.deliveryId.toString(),
              suhu: suhuBoxController.text,
            );
      }
    }

    // save work input suhu provider
    ref.listen(workInputSuhuSave, (prev, next) {
      if (next is WorkInputSuhuStateLoading) {
        detailLoading.value = true;
      } else if (next is WorkInputSuhuStateError) {
        detailLoading.value = false;
        errorMessage.value = next.message ?? "";
        SanckbarWidget(context, "${next.message}", snackbarType.error);
        Timer(const Duration(seconds: 3), () {
          errorMessage.value = "";
        });
      } else if (next is WorkInputSuhuStateDone) {
        detailLoading.value = false;
        if (next.model.status != "OK") {
          SanckbarWidget(context, "${next.model.message}", snackbarType.error);
        } else {
          SanckbarWidget(
              context, "Suhu Berhasil Di update", snackbarType.success);

          getLocationStep.value = getLocationStepEnum.pengambilanAwal;
        }
      }
    });
    // SUHU PROVIDER AND FUNCTION END

    useEffect(() {
      WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
        requestLocationPermission();
        fetchData();
      });
      return () {};
    }, []);

    // WORK TUNDA PROVIDER AND FUNCTION START
    saveWorkTunda({required String note}) {
      if (ctrlNoteTunda.text.isEmpty) {
        SanckbarWidget(
            context, "Alasan Tunda Harus Diisi", snackbarType.warning);
      } else {
        final param = {
          "id": data.kurirId.toString(),
          "tipeid": data.tipeId.toString(),
          "deliveryid": data.deliveryId,
          "note": note
        };

        print("param : $param");

        ref.read(workTundaSave.notifier).WorkTundaSave(
              deliveryID: data.deliveryId,
              tipeID: data.tipeId.toString(),
              courierID: data.kurirId.toString(),
              note: note,
            );
      }
    }

    // save tunda provider
    ref.listen(workTundaSave, (prev, next) {
      if (next is WorkTundaSaveStateLoading) {
        detailLoading.value = true;
      } else if (next is WorkTundaSaveStateError) {
        detailLoading.value = false;
        errorMessage.value = next.message ?? "";
        SanckbarWidget(context, "${next.message}", snackbarType.error);
        Timer(const Duration(seconds: 3), () {
          errorMessage.value = "";
        });
      } else if (next is WorkTundaSaveStateDone) {
        detailLoading.value = false;
        if (next.model.status != "OK") {
          SanckbarWidget(context, "${next.model.message}", snackbarType.error);
        } else {
          SanckbarWidget(
              context, "Tunda Pekerjaan Berhasil", snackbarType.success);
          Navigator.of(context).pop();
          // Navigator.of(context).pop();
        }
      }
    });
    // WORK TUNDA PROVIDER AND FUNCTION END

    return RefreshIndicator(
      onRefresh: () async {
        fetchData();
      },
      child: Stack(
        children: [
          Scaffold(
            resizeToAvoidBottomInset: false,
            // extendBody: false,
            backgroundColor: Colors.white,
            bottomNavigationBar: buttonLocation.value || buttonSave.value
                ? Container(
                    // color: Colors.blue,
                    padding: EdgeInsets.symmetric(
                        horizontal:
                            Constant.getActualX(context: context, x: 35)),
                    height: Constant.getActualY(context: context, y: 70),
                    child: Column(
                      children: [
                        if (buttonLocation.value &&
                            !detailLoading.value &&
                            kurirKonfirmasi.value)
                          SizedBox(
                            // color: Colors.red,
                            height:
                                Constant.getActualY(context: context, y: 46),
                            child: ElevatedButton(
                                onPressed: () {
                                  getLocation(context);
                                },
                                style: ElevatedButton.styleFrom(
                                  shape: RoundedRectangleBorder(
                                    side: const BorderSide(
                                        width: 0.1, color: Colors.grey),
                                    borderRadius: BorderRadius.circular(8),
                                  ),
                                ),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Icon(Icons.location_searching_rounded),
                                    SizedBox(
                                      width: Constant.getActualX(
                                          context: context, x: 8),
                                    ),
                                    const Text(
                                      "Gunakan Lokasi Saat Ini",
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold),
                                    )
                                  ],
                                )),
                          ),
                        if (buttonSave.value &&
                            !detailLoading.value &&
                            kurirKonfirmasi.value)
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              OutlinedButton(
                                  onPressed: () {
                                    Navigator.pop(context);
                                  },
                                  style: OutlinedButton.styleFrom(
                                    side: BorderSide(
                                        style: BorderStyle.solid,
                                        color: Constant.primaryBlue),
                                    shape: RoundedRectangleBorder(
                                      side: BorderSide(
                                          style: BorderStyle.solid,
                                          color: Constant.primaryBlue),
                                      borderRadius: BorderRadius.circular(8),
                                    ),
                                  ),
                                  child: const Text(
                                    "Batal",
                                    style:
                                        TextStyle(fontWeight: FontWeight.bold),
                                  )),
                              ElevatedButton(
                                  onPressed:
                                      catatanController.text.isNotEmpty &&
                                              petugasPenyerahanController
                                                  .text.isNotEmpty
                                          ? () {
                                              saveCatatan();
                                            }
                                          : null,
                                  style: ElevatedButton.styleFrom(
                                    shape: RoundedRectangleBorder(
                                      side: const BorderSide(
                                          width: 0.1, color: Colors.grey),
                                      borderRadius: BorderRadius.circular(8),
                                    ),
                                  ),
                                  child: const Text(
                                    "Simpan",
                                    style:
                                        TextStyle(fontWeight: FontWeight.bold),
                                  ))
                            ],
                          ),
                        if (!buttonSave.value &&
                            !detailLoading.value &&
                            !kurirKonfirmasi.value &&
                            !sudahAdaLokasiAwal.value)
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              OutlinedButton(
                                  onPressed: () {
                                    showConfirmCourierDialog(
                                      context: context,
                                      tipe: "Tolak",
                                      tipeid: data.tipeId,
                                      tipee: "${detailData.value.tipe}",
                                      tujuann: data.tujuan,
                                      noteKurir: noteKurir,
                                      penerimaa:
                                          "${detailData.value.alamatPengantaran}",
                                      okCallback: () {
                                        // print(noteKurir.text);

                                        if (noteKurir.text.isEmpty) {
                                          SanckbarWidget(
                                              context,
                                              "Alasan Tolak Wajib Diisi",
                                              snackbarType.warning);
                                          return;
                                        } else {
                                          ref
                                              .read(kurirTolakProvider.notifier)
                                              .tolakKurir(
                                                id: data.kurirId,
                                                tipeId: data.tipeId.toString(),
                                                deliveryId: data.deliveryId,
                                                note: noteKurir.text,
                                              );
                                        }
                                      },
                                    );
                                  },
                                  style: OutlinedButton.styleFrom(
                                    side: BorderSide(
                                        style: BorderStyle.solid,
                                        color: Constant.primaryRed),
                                    shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(8),
                                    ),
                                  ),
                                  child: const Text("Tolak",
                                      style: TextStyle(
                                          fontWeight: FontWeight.bold,
                                          color: Colors.red))),
                              ElevatedButton(
                                  onPressed: () {
                                    showConfirmCourierDialog(
                                      context: context,
                                      tipe: "Terima",
                                      tipeid: data.tipeId,
                                      tipee: "${detailData.value.tipe}",
                                      tujuann: data.tujuan,
                                      penerimaa:
                                          "${detailData.value.alamatPengantaran}",
                                      noteKurir: noteKurir,
                                      okCallback: () {
                                        kurirKonfirmasi.value = true;
                                        getLocationStep.value =
                                            getLocationStepEnum.pengambilanAwal;

                                        // getLocationStep.value =
                                        //     getLocationStepEnum.inputSuhu;
                                      },
                                    );
                                  },
                                  style: ElevatedButton.styleFrom(
                                    shape: RoundedRectangleBorder(
                                      side: const BorderSide(
                                          width: 0.1, color: Colors.blue),
                                      borderRadius: BorderRadius.circular(8),
                                    ),
                                  ),
                                  child: const Text(
                                    "Terima",
                                    style:
                                        TextStyle(fontWeight: FontWeight.bold),
                                  ))
                            ],
                          ),
                      ],
                    ),
                  )
                : null,
            body: detailLoading.value
                ? Center(
                    child: LoadingAnimationWidget.fourRotatingDots(
                        color: Constant.primaryBlue, size: 50),
                  )
                : ListView(
                    children: [
                      Container(
                        // color: Colors.white,
                        height: Constant.getActualY(context: context, y: 56),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(
                            horizontal:
                                Constant.getActualX(context: context, x: 10)),
                        // color: Colors.white,
                        height: Constant.getActualY(context: context, y: 48),
                        child: Row(
                          children: [
                            IconButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                              icon: const Icon(Icons.arrow_back_ios_rounded),
                            ),
                            Expanded(
                              child: Text(
                                "${detailData.value.tipe}",
                                style: Constant.body1(context: context)
                                    .copyWith(
                                        fontWeight: FontWeight.w600,
                                        color: Constant.textPrimary),
                              ),
                            ),
                            if (buttonTundaShow.value == true)
                              InkWell(
                                onTap: () {
                                  print('OPEN DIALOG TUNDA');
                                  // OPEN DIALOG TUNDA START
                                  showDialog(
                                    context: context,
                                    builder: (BuildContext context) {
                                      return AlertDialog(
                                        title: const Text(
                                          "Tunda Pekerjaan",
                                          style: TextStyle(
                                              fontWeight: FontWeight.bold),
                                        ),
                                        content: SizedBox(
                                          height: Constant.getActualY(
                                              context: context, y: 270),
                                          child: Column(
                                            crossAxisAlignment:
                                                CrossAxisAlignment.start,
                                            children: [
                                              Text(
                                                "Anda akan menunda pekerjaan ini ?",
                                                textAlign: TextAlign.left,
                                                style: Constant.body2(
                                                        context: context)
                                                    .copyWith(
                                                        fontWeight:
                                                            FontWeight.w400,
                                                        color: Constant
                                                            .textPrimary),
                                              ),
                                              Container(
                                                margin:
                                                    const EdgeInsets.fromLTRB(
                                                        0, 16, 0, 25),
                                                width: double.infinity,
                                                child: Card(
                                                  elevation: 2,
                                                  shape: RoundedRectangleBorder(
                                                    side: BorderSide(
                                                      color: Theme.of(context)
                                                          .colorScheme
                                                          .outline,
                                                    ),
                                                    borderRadius:
                                                        const BorderRadius.all(
                                                            Radius.circular(
                                                                12)),
                                                  ),
                                                  child: Container(
                                                    padding:
                                                        const EdgeInsets.all(
                                                            16),
                                                    child: Column(
                                                      children: [
                                                        Row(
                                                          children: [
                                                            Expanded(
                                                              flex: 3,
                                                              child: Text(
                                                                "Tipe",
                                                                style: Constant
                                                                    .caption1(
                                                                        context:
                                                                            context),
                                                              ),
                                                            ),
                                                            // widget card dialog tunda
                                                            if (data.tipeId ==
                                                                5)
                                                              cardDialogTundaTipe(
                                                                context,
                                                                detailData
                                                                    .value.tipe,
                                                                Constant
                                                                    .backgroundBlue,
                                                                Constant
                                                                    .primaryBlue,
                                                              ),
                                                            if (data.tipeId ==
                                                                1)
                                                              cardDialogTundaTipe(
                                                                context,
                                                                detailData
                                                                    .value.tipe,
                                                                Constant
                                                                    .backgroundOrange,
                                                                Constant
                                                                    .primaryOrange,
                                                              ),
                                                            if (data.tipeId ==
                                                                3)
                                                              cardDialogTundaTipe(
                                                                context,
                                                                detailData
                                                                    .value.tipe,
                                                                Constant
                                                                    .backgroundGreen,
                                                                Constant
                                                                    .primaryGreen,
                                                              ),
                                                            if (data.tipeId ==
                                                                2)
                                                              cardDialogTundaTipe(
                                                                context,
                                                                detailData
                                                                    .value.tipe,
                                                                Constant
                                                                    .backgroundPurple,
                                                                Constant
                                                                    .primaryPurple,
                                                              ),
                                                            if (data.tipeId ==
                                                                4)
                                                              cardDialogTundaTipe(
                                                                context,
                                                                detailData
                                                                    .value.tipe,
                                                                Constant
                                                                    .primaryRed
                                                                    .withOpacity(
                                                                        0.25),
                                                                Constant
                                                                    .primaryRed,
                                                              ),
                                                          ],
                                                        ),
                                                        Row(
                                                          children: [
                                                            Expanded(
                                                              flex: 3,
                                                              child: Text(
                                                                "Tujuan",
                                                                style: Constant
                                                                    .caption1(
                                                                        context:
                                                                            context),
                                                              ),
                                                            ),
                                                            Expanded(
                                                              flex: 5,
                                                              child: Text(
                                                                detailData.value
                                                                        .alamatPengambilan ??
                                                                    "",
                                                                style:
                                                                    TextStyle(
                                                                  color: Constant
                                                                      .textGrey,
                                                                  fontSize: 12,
                                                                ),
                                                              ),
                                                            )
                                                          ],
                                                        ),
                                                        Row(
                                                          children: [
                                                            Expanded(
                                                              flex: 3,
                                                              child: Text(
                                                                "Penerima",
                                                                style: Constant
                                                                    .caption1(
                                                                        context:
                                                                            context),
                                                              ),
                                                            ),
                                                            Expanded(
                                                              flex: 5,
                                                              child: Text(
                                                                detailData.value
                                                                        .alamatPengantaran ??
                                                                    "",
                                                                style:
                                                                    TextStyle(
                                                                  color: Constant
                                                                      .textGrey,
                                                                  fontSize: 12,
                                                                ),
                                                              ),
                                                            )
                                                          ],
                                                        ),
                                                      ],
                                                    ),
                                                  ),
                                                ),
                                              ),
                                              SizedBox(
                                                // width: Constant.getActualX(context: context, x: 250),
                                                height: Constant.getActualY(
                                                    context: context, y: 50),
                                                child: TextFormField(
                                                  controller: ctrlNoteTunda,
                                                  decoration: InputDecoration(
                                                    labelStyle: TextStyle(
                                                        color: Colors.grey),
                                                    border: OutlineInputBorder(
                                                        borderSide: BorderSide(
                                                            color: Colors.grey),
                                                        borderRadius:
                                                            BorderRadius.all(
                                                                Radius.circular(
                                                                    12))),
                                                    labelText: 'Alasan',
                                                  ),
                                                ),
                                              )
                                            ],
                                          ),
                                        ),
                                        actions: [
                                          Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceEvenly,
                                            children: [
                                              OutlinedButton(
                                                onPressed: () {
                                                  ctrlNoteTunda.text = "";
                                                  Navigator.pop(
                                                      context, 'Cancel');
                                                },
                                                style: OutlinedButton.styleFrom(
                                                  side: BorderSide(
                                                      style: BorderStyle.solid,
                                                      color: Constant.textGrey),
                                                  shape: RoundedRectangleBorder(
                                                    side: BorderSide(
                                                        style:
                                                            BorderStyle.solid,
                                                        color: Constant
                                                            .textPrimary),
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            8),
                                                  ),
                                                ),
                                                child: const Text(
                                                  "Batal",
                                                  style: TextStyle(
                                                    fontWeight: FontWeight.bold,
                                                    color: Colors.black,
                                                  ),
                                                ),
                                              ),
                                              const Padding(
                                                padding: EdgeInsets.fromLTRB(
                                                    0, 0, 65, 0),
                                              ),
                                              ElevatedButton(
                                                onPressed: () {
                                                  // print(ctrlNoteTunda.text);
                                                  if (ctrlNoteTunda
                                                      .text.isNotEmpty) {
                                                    saveWorkTunda(
                                                        note:
                                                            ctrlNoteTunda.text);
                                                  } else {
                                                    SanckbarWidget(
                                                        context,
                                                        "Alasan tunda tidak boleh kososng",
                                                        snackbarType.warning);
                                                  }
                                                },
                                                style: ElevatedButton.styleFrom(
                                                  backgroundColor: Colors.red,
                                                  shape: RoundedRectangleBorder(
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            8),
                                                  ),
                                                ),
                                                child: const Text(
                                                  "Tunda",
                                                  style: TextStyle(
                                                      fontWeight:
                                                          FontWeight.bold),
                                                ),
                                              ),
                                            ],
                                          )
                                        ],
                                        shape: RoundedRectangleBorder(
                                          side: BorderSide(
                                            color: Theme.of(context)
                                                .colorScheme
                                                .outline,
                                          ),
                                          borderRadius: const BorderRadius.all(
                                            Radius.circular(12),
                                          ),
                                        ),
                                      );
                                    },
                                  );
                                  // OPEN DIALOG TUNDA END
                                },
                                child: Container(
                                  width: Constant.getActualY(
                                      context: context, y: 30),
                                  height: Constant.getActualY(
                                      context: context, y: 30),
                                  decoration: BoxDecoration(
                                    color: Color(0xffFF4842),
                                    borderRadius: BorderRadius.circular(12),
                                  ),
                                  child: Icon(
                                    Icons.timer_off,
                                    color: Colors.white,
                                    size: 18,
                                  ),
                                ),
                              ),
                          ],
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.symmetric(
                            horizontal:
                                Constant.getActualX(context: context, x: 35)),
                        // color: Colors.red,
                        height: Constant.getActualY(
                            context: context,
                            y: buttonLocation.value || buttonSave.value
                                ? 650
                                : 737),
                        child: SingleChildScrollView(
                          reverse: MediaQuery.of(context).viewInsets.bottom != 0
                              ? true
                              : false,
                          child: Padding(
                            padding: EdgeInsets.only(
                                bottom:
                                    MediaQuery.of(context).viewInsets.bottom),
                            child: Column(
                              // shrinkWrap: true,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                if (data.tipeId == 5)
                                  headerCard(context, Constant.backgroundBlue,
                                      "Ambil Bahan", Constant.primaryBlue),
                                if (data.tipeId == 1)
                                  headerCard(context, Constant.backgroundOrange,
                                      "Ambil Hasil", Constant.primaryOrange),
                                if (data.tipeId == 3)
                                  headerCard(context, Constant.backgroundGreen,
                                      "Ambil Hasil", Constant.primaryGreen),
                                if (data.tipeId == 2)
                                  headerCard(context, Constant.backgroundPurple,
                                      "Ambil Hasil", Constant.primaryPurple),
                                if (data.tipeId == 4)
                                  headerCard(
                                      context,
                                      Constant.primaryRed.withOpacity(0.25),
                                      "Ambil Hasil",
                                      Constant.primaryRed),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 20),
                                ),
                                if (data.tipeId == 1)
                                  Column(
                                    children: [
                                      // Text(address.value),
                                      displayDetailText(
                                          context, "Nomor Lab", data.nomorLab),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(
                                          context, "Nama", data.tujuan),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(context, "Catatan FO",
                                          detailData.value.foNote ?? ""),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(
                                          context,
                                          "Catatan Admin",
                                          detailData.value.adminNote ?? ""),
                                    ],
                                  ),
                                if (data.tipeId == 2)
                                  Column(
                                    children: [
                                      displayDetailText(
                                          context,
                                          "No. Surat jalan",
                                          detailData.value.noSuratJalan
                                              .toString()),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(context, "Nama",
                                          detailData.value.nama.toString()),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(
                                          context,
                                          "Catatan Admin",
                                          detailData.value.adminNote ?? ""),
                                    ],
                                  ),
                                if (data.tipeId == 3)
                                  Column(
                                    children: [
                                      displayDetailText(
                                          context,
                                          "No. Surat jalan",
                                          detailData.value.noSuratJalan
                                              .toString()),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(context, "Nama",
                                          detailData.value.nama.toString()),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(
                                          context,
                                          "Catatan Admin",
                                          detailData.value.adminNote ?? ""),
                                    ],
                                  ),
                                if (data.tipeId == 4)
                                  Column(
                                    children: [
                                      displayDetailText(
                                          context, "Catatan", data.catatanFo),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(
                                          context,
                                          "Catatan Admin",
                                          detailData.value.adminNote ?? ""),
                                    ],
                                  ),
                                if (data.tipeId == 5)
                                  Column(
                                    children: [
                                      displayDetailText(
                                          context, "Tujuan", data.tujuan),
                                      SizedBox(
                                        height: Constant.getActualY(
                                            context: context, y: 12),
                                      ),
                                      displayDetailText(
                                          context,
                                          "Catatan Admin",
                                          detailData.value.adminNote ?? ""),
                                    ],
                                  ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                if (data.tipeId == 1 ||
                                    data.tipeId == 2 ||
                                    data.tipeId == 3)
                                  Text(
                                    "Pengambilan Hasil",
                                    // maxLines: 5,
                                    overflow: TextOverflow.visible,
                                    style: Constant.body1(context: context)
                                        .copyWith(
                                            fontWeight: FontWeight.w600,
                                            color: Constant.textPrimary),
                                  ),
                                if (data.tipeId == 5)
                                  Text(
                                    "Pengambilan Bahan",
                                    // maxLines: 5,
                                    overflow: TextOverflow.visible,
                                    style: Constant.body1(context: context)
                                        .copyWith(
                                            fontWeight: FontWeight.w600,
                                            color: Constant.textPrimary),
                                  ),
                                if (data.tipeId == 4)
                                  Text(
                                    "Pengirim",
                                    // maxLines: 5,
                                    overflow: TextOverflow.visible,
                                    style: Constant.body1(context: context)
                                        .copyWith(
                                            fontWeight: FontWeight.w600,
                                            color: Constant.textPrimary),
                                  ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Expanded(
                                      child: Text(
                                        "Alamat Pengambilan",
                                        style: Constant.body3(context: context)
                                            .copyWith(
                                                fontWeight: FontWeight.w400,
                                                color: Constant.textPrimary),
                                      ),
                                    ),
                                    Expanded(
                                      child: SelectableText(
                                        ": ${detailData.value.alamatPengambilan}",
                                        style: Constant.body3(context: context)
                                            .copyWith(
                                                fontWeight: FontWeight.w400,
                                                color: Constant.textPrimary),
                                      ),
                                    )
                                  ],
                                ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                // SUHU
                                if (data.tipeId == 5 &&
                                    kurirKonfirmasi.value == true)
                                  Row(
                                    children: [
                                      Expanded(
                                        child: TextFormField(
                                          controller: suhuBoxController,
                                          keyboardType: TextInputType.number,
                                          onFieldSubmitted: saveWorkInputSuhu,
                                          enabled:
                                              (suhuBoxController.text.isEmpty)
                                                  ? true
                                                  : false,
                                          decoration: InputDecoration(
                                            hintText:
                                                "Suhu Box (Dalam Celcius)",
                                            // label: "Petugas Penyerahan" ,
                                            labelText:
                                                "Suhu Box (Dalam Celcius)",
                                            border: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(8),
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                // END SUHU
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Row(
                                      children: [
                                        if (pengambilanAwalLoc.value["lat"] ==
                                                "" ||
                                            pengambilanAwalLoc.value['long'] ==
                                                "")
                                          Icon(
                                            Icons.location_on,
                                            color: getLocationStep.value ==
                                                    getLocationStepEnum
                                                        .pengambilanAwal
                                                ? Constant.primaryBlue
                                                : Colors.grey,
                                          ),
                                        if (pengambilanAwalLoc.value["lat"] ==
                                                "" ||
                                            pengambilanAwalLoc.value['long'] ==
                                                "")
                                          SizedBox(
                                            width: Constant.getActualX(
                                                context: context, x: 4),
                                          ),
                                        Text(
                                          "Lokasi Awal",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        )
                                      ],
                                    ),
                                    if (pengambilanAwalLoc.value["lat"] != "" ||
                                        pengambilanAwalLoc.value['long'] != "")
                                      InkWell(
                                        onTap: () {
                                          MapsLauncher.launchCoordinates(
                                              double.parse(pengambilanAwalLoc
                                                  .value["lat"]!),
                                              double.parse(pengambilanAwalLoc
                                                  .value["long"]!));
                                        },
                                        child: Row(
                                          children: [
                                            Text(
                                              "Sudah ditandai",
                                              style: Constant.body3(
                                                      context: context)
                                                  .copyWith(
                                                      fontWeight:
                                                          FontWeight.w600,
                                                      color:
                                                          Constant.primaryBlue),
                                            ),
                                            SizedBox(
                                              width: Constant.getActualX(
                                                  context: context, x: 4),
                                            ),
                                            Icon(
                                              Icons.map_outlined,
                                              color: Constant.primaryBlue,
                                            ),
                                          ],
                                        ),
                                      ),
                                  ],
                                ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Row(
                                      children: [
                                        if (pengambilanAkhirLoc.value["lat"] ==
                                                "" ||
                                            pengambilanAkhirLoc.value['long'] ==
                                                "")
                                          Icon(
                                            Icons.location_on,
                                            color: getLocationStep.value ==
                                                    getLocationStepEnum
                                                        .pengambilanAkhir
                                                ? Constant.primaryBlue
                                                : Colors.grey,
                                          ),
                                        if (pengambilanAkhirLoc.value["lat"] ==
                                                "" ||
                                            pengambilanAkhirLoc.value['long'] ==
                                                "")
                                          SizedBox(
                                            width: Constant.getActualX(
                                                context: context, x: 4),
                                          ),
                                        Text(
                                          "Lokasi Akhir",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: getLocationStep
                                                              .value ==
                                                          getLocationStepEnum
                                                              .pengambilanAkhir
                                                      ? Constant.textPrimary
                                                      : pengambilanAkhirLoc
                                                                          .value[
                                                                      "lat"] ==
                                                                  "" ||
                                                              pengambilanAkhirLoc
                                                                          .value[
                                                                      'long'] ==
                                                                  ""
                                                          ? Colors.grey
                                                          : Constant
                                                              .textPrimary),
                                        )
                                      ],
                                    ),
                                    if (pengambilanAkhirLoc.value["lat"] !=
                                            "" ||
                                        pengambilanAkhirLoc.value['long'] != "")
                                      InkWell(
                                        onTap: () {
                                          MapsLauncher.launchCoordinates(
                                              double.parse(pengambilanAkhirLoc
                                                  .value["lat"]!),
                                              double.parse(pengambilanAkhirLoc
                                                  .value["long"]!));
                                        },
                                        child: Row(
                                          children: [
                                            Text(
                                              "Sudah ditandai",
                                              style: Constant.body3(
                                                      context: context)
                                                  .copyWith(
                                                      fontWeight:
                                                          FontWeight.w600,
                                                      color:
                                                          Constant.primaryBlue),
                                            ),
                                            SizedBox(
                                              width: Constant.getActualX(
                                                  context: context, x: 4),
                                            ),
                                            Icon(
                                              Icons.map_outlined,
                                              color: Constant.primaryBlue,
                                            ),
                                          ],
                                        ),
                                      ),
                                  ],
                                ),
                                if (petugasPengambilan.value.isNotEmpty ||
                                    catatanPengambilan.value.isNotEmpty)
                                  SizedBox(
                                    height: Constant.getActualY(
                                        context: context, y: 12),
                                  ),
                                if (petugasPengambilan.value.isNotEmpty ||
                                    catatanPengambilan.value.isNotEmpty)
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Expanded(
                                        child: Text(
                                          "Petugas Penyerahan",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      ),
                                      Expanded(
                                        child: Text(
                                          " : ${petugasPengambilan.value}",
                                          maxLines: 2,
                                          overflow: TextOverflow.ellipsis,
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      )
                                    ],
                                  ),
                                if (petugasPengambilan.value.isNotEmpty ||
                                    catatanPengambilan.value.isNotEmpty)
                                  SizedBox(
                                    height: Constant.getActualY(
                                        context: context, y: 12),
                                  ),
                                if (petugasPengambilan.value.isNotEmpty ||
                                    catatanPengambilan.value.isNotEmpty)
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Expanded(
                                        child: Text(
                                          "Catatan",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      ),
                                      Expanded(
                                        child: Text(
                                          " : ${catatanPengambilan.value} ",
                                          overflow: TextOverflow.visible,
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      )
                                    ],
                                  ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                if (data.tipeId == 1 ||
                                    data.tipeId == 2 ||
                                    data.tipeId == 3)
                                  Text(
                                    "Pengantaran Hasil",
                                    // maxLines: 5,
                                    overflow: TextOverflow.visible,
                                    style: Constant.body1(context: context)
                                        .copyWith(
                                            fontWeight: FontWeight.w600,
                                            color: Constant.textPrimary),
                                  ),
                                if (data.tipeId == 5)
                                  Text(
                                    "Pengantaran Bahan",
                                    // maxLines: 5,
                                    overflow: TextOverflow.visible,
                                    style: Constant.body1(context: context)
                                        .copyWith(
                                            fontWeight: FontWeight.w600,
                                            color: Constant.textPrimary),
                                  ),
                                if (data.tipeId == 4)
                                  Text(
                                    "Penerima",
                                    // maxLines: 5,
                                    overflow: TextOverflow.visible,
                                    style: Constant.body1(context: context)
                                        .copyWith(
                                            fontWeight: FontWeight.w600,
                                            color: Constant.textPrimary),
                                  ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.start,
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Expanded(
                                      child: Text(
                                        "Alamat Pengantaran",
                                        style: Constant.body3(context: context)
                                            .copyWith(
                                                fontWeight: FontWeight.w400,
                                                color: Constant.textPrimary),
                                      ),
                                    ),
                                    Expanded(
                                      child: SelectableText(
                                        ": ${detailData.value.alamatPengantaran}",
                                        style: Constant.body3(context: context)
                                            .copyWith(
                                                fontWeight: FontWeight.w400,
                                                color: Constant.textPrimary),
                                      ),
                                    )
                                  ],
                                ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Row(
                                      children: [
                                        if (pengantaranAwalLoc.value["lat"] ==
                                                "" ||
                                            pengantaranAwalLoc.value['long'] ==
                                                "")
                                          Icon(
                                            Icons.location_on,
                                            color: getLocationStep.value ==
                                                    getLocationStepEnum
                                                        .pengantaranAwal
                                                ? Constant.primaryBlue
                                                : Colors.grey,
                                          ),
                                        if (pengantaranAwalLoc.value["lat"] ==
                                                "" ||
                                            pengantaranAwalLoc.value['long'] ==
                                                "")
                                          SizedBox(
                                            width: Constant.getActualX(
                                                context: context, x: 4),
                                          ),
                                        Text(
                                          "Lokasi Awal",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: getLocationStep
                                                              .value ==
                                                          getLocationStepEnum
                                                              .pengantaranAwal
                                                      ? Constant.textPrimary
                                                      : pengantaranAwalLoc.value[
                                                                      "lat"] ==
                                                                  "" ||
                                                              pengantaranAwalLoc
                                                                          .value[
                                                                      'long'] ==
                                                                  ""
                                                          ? Colors.grey
                                                          : Constant
                                                              .textPrimary),
                                        )
                                      ],
                                    ),
                                    if (pengantaranAwalLoc.value["lat"] != "" ||
                                        pengantaranAwalLoc.value['long'] != "")
                                      InkWell(
                                        onTap: () {
                                          MapsLauncher.launchCoordinates(
                                              double.parse(pengantaranAwalLoc
                                                  .value["lat"]!),
                                              double.parse(pengantaranAwalLoc
                                                  .value["long"]!));
                                        },
                                        child: Row(
                                          children: [
                                            Text(
                                              "Sudah ditandai",
                                              style: Constant.body3(
                                                      context: context)
                                                  .copyWith(
                                                      fontWeight:
                                                          FontWeight.w600,
                                                      color:
                                                          Constant.primaryBlue),
                                            ),
                                            SizedBox(
                                              width: Constant.getActualX(
                                                  context: context, x: 4),
                                            ),
                                            Icon(
                                              Icons.map_outlined,
                                              color: Constant.primaryBlue,
                                            ),
                                          ],
                                        ),
                                      ),
                                  ],
                                ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 12),
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    Row(
                                      children: [
                                        if (pengantaranAkhirLoc.value["lat"] ==
                                                "" ||
                                            pengantaranAkhirLoc.value['long'] ==
                                                "")
                                          Icon(
                                            Icons.location_on,
                                            color: getLocationStep.value ==
                                                    getLocationStepEnum
                                                        .pengantaranAkhir
                                                ? Constant.primaryBlue
                                                : Colors.grey,
                                          ),
                                        if (pengantaranAkhirLoc.value["lat"] ==
                                                "" ||
                                            pengantaranAkhirLoc.value['long'] ==
                                                "")
                                          SizedBox(
                                            width: Constant.getActualX(
                                                context: context, x: 4),
                                          ),
                                        Text(
                                          "Lokasi Akhir",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: getLocationStep
                                                              .value ==
                                                          getLocationStepEnum
                                                              .pengantaranAkhir
                                                      ? Constant.textPrimary
                                                      : pengantaranAwalLoc.value[
                                                                      "lat"] ==
                                                                  "" ||
                                                              pengantaranAwalLoc
                                                                          .value[
                                                                      'long'] ==
                                                                  ""
                                                          ? Colors.grey
                                                          : Constant
                                                              .textPrimary),
                                        )
                                      ],
                                    ),
                                    if (pengantaranAkhirLoc.value["lat"] !=
                                            "" ||
                                        pengantaranAkhirLoc.value['long'] != "")
                                      InkWell(
                                        onTap: () {
                                          MapsLauncher.launchCoordinates(
                                              double.parse(pengantaranAkhirLoc
                                                  .value["lat"]!),
                                              double.parse(pengantaranAkhirLoc
                                                  .value["long"]!));
                                        },
                                        child: Row(
                                          children: [
                                            Text(
                                              "Sudah ditandai",
                                              style: Constant.body3(
                                                      context: context)
                                                  .copyWith(
                                                      fontWeight:
                                                          FontWeight.w600,
                                                      color:
                                                          Constant.primaryBlue),
                                            ),
                                            SizedBox(
                                              width: Constant.getActualX(
                                                  context: context, x: 4),
                                            ),
                                            Icon(
                                              Icons.map_outlined,
                                              color: Constant.primaryBlue,
                                            ),
                                          ],
                                        ),
                                      ),
                                  ],
                                ),
                                if (petugasPengantaran.value.isNotEmpty ||
                                    catatanPengantaran.value.isNotEmpty)
                                  SizedBox(
                                    height: Constant.getActualY(
                                        context: context, y: 12),
                                  ),
                                if (petugasPengantaran.value.isNotEmpty ||
                                    catatanPengantaran.value.isNotEmpty)
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Expanded(
                                        child: Text(
                                          "Penerima",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      ),
                                      Expanded(
                                        child: Text(
                                          " : ${petugasPengantaran.value}",
                                          maxLines: 2,
                                          overflow: TextOverflow.ellipsis,
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      )
                                    ],
                                  ),
                                if (petugasPengantaran.value.isNotEmpty ||
                                    catatanPengantaran.value.isNotEmpty)
                                  SizedBox(
                                    height: Constant.getActualY(
                                        context: context, y: 12),
                                  ),
                                if (petugasPengantaran.value.isNotEmpty ||
                                    catatanPengantaran.value.isNotEmpty)
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Expanded(
                                        child: Text(
                                          "Catatan",
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      ),
                                      Expanded(
                                        child: Text(
                                          " : ${catatanPengantaran.value} ",
                                          overflow: TextOverflow.visible,
                                          style: Constant.body3(
                                                  context: context)
                                              .copyWith(
                                                  fontWeight: FontWeight.w400,
                                                  color: Constant.textPrimary),
                                        ),
                                      )
                                    ],
                                  ),
                                if (detailData.value.patients != null)
                                  ExpansionTile(
                                    tilePadding: const EdgeInsets.symmetric(
                                        horizontal: 0),
                                    title: Text(
                                      "List (${detailData.value.patients?.length} pasien)",
                                      style: Constant.body3(context: context)
                                          .copyWith(
                                              fontWeight: FontWeight.w400),
                                    ),
                                    children: detailData.value.patients!
                                        .map((e) => PatientCard(
                                              name: e.pasien.toString(),
                                              noLab: e.tOrderHeaderLabNumber
                                                  .toString(),
                                              note: e.courierConfirmNote,
                                              // onClick: () {
                                              //   print(e['name']);
                                              // },
                                            ))
                                        .toList(),
                                  ),
                                SizedBox(
                                  height: Constant.getActualY(
                                      context: context, y: 20),
                                ),
                                if (getLocationStep.value == getLocationStepEnum.catatanPengambilan ||
                                    getLocationStep.value ==
                                        getLocationStepEnum
                                            .catatanPengantaran ||
                                    showPetugasPenyerahan.value)
                                  TextFormField(
                                    controller: petugasPenyerahanController,
                                    enabled: (getLocationStep.value ==
                                            getLocationStepEnum.done)
                                        ? false
                                        : true,
                                    decoration: InputDecoration(
                                      hintText: getLocationStep.value ==
                                              getLocationStepEnum
                                                  .catatanPengambilan
                                          ? "Petugas Penyerahan"
                                          : "Penerima",
                                      // label: "Petugas Penyerahan" ,
                                      labelText: getLocationStep.value ==
                                              getLocationStepEnum
                                                  .catatanPengambilan
                                          ? "Petugas Penyerahan"
                                          : "Penerima",
                                      border: OutlineInputBorder(
                                          borderRadius:
                                              BorderRadius.circular(8)),
                                    ),
                                  ),
                                if (getLocationStep.value == getLocationStepEnum.catatanPengambilan ||
                                    getLocationStep.value ==
                                        getLocationStepEnum
                                            .catatanPengantaran ||
                                    getLocationStep.value ==
                                        getLocationStepEnum.done)
                                  SizedBox(
                                    height: Constant.getActualY(
                                        context: context, y: 12),
                                  ),
                                if (getLocationStep.value == getLocationStepEnum.catatanPengambilan ||
                                    getLocationStep.value ==
                                        getLocationStepEnum
                                            .catatanPengantaran ||
                                    showCatatan.value)
                                  TextFormField(
                                    controller: catatanController,
                                    onChanged: (value) {
                                      if (data.tipeId == 5 &&
                                          getLocationStep.value ==
                                              getLocationStepEnum
                                                  .catatanPengambilan &&
                                          petugasPenyerahanController
                                              .text.isNotEmpty) {
                                        // show info
                                        hideInfo.value = true;
                                      }
                                    },
                                    keyboardType: TextInputType.multiline,
                                    maxLines: 3,
                                    enabled: (getLocationStep.value ==
                                            getLocationStepEnum.done)
                                        ? false
                                        : true,
                                    decoration: InputDecoration(
                                      hintText: "Catatan",
                                      labelText: "Catatan",
                                      border: OutlineInputBorder(
                                          borderRadius:
                                              BorderRadius.circular(8)),
                                    ),
                                  ),
                                // ADD INFO JIKA data.tipeId == 5
                                // if (data.tipeId == 5 && hideInfo.value)
                                if (data.tipeId == 5 && hideInfo.value)
                                  Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: pengambilanBahanInfo(
                                        context,
                                        data.tipeId,
                                        jumlahPasienController,
                                        edtaRutinController,
                                        darahCitrasController,
                                        serumController,
                                        urineController,
                                        pleuraController,
                                        otherTextBahanController,
                                        totalOtherController,
                                        getLocationStep),
                                  ),
                                // END ADD INFO

                                // SUHU BOX BOTTOM START
                                if (showSuhuBoxBottom.value && data.tipeId == 5)
                                  SizedBox(
                                    height: Constant.getActualY(
                                        context: context, y: 12),
                                  ),
                                if (showSuhuBoxBottom.value && data.tipeId == 5)
                                  Row(
                                    children: [
                                      Expanded(
                                        child: TextFormField(
                                          controller: suhuSampleController,
                                          enabled: (getLocationStep.value ==
                                                  getLocationStepEnum.done)
                                              ? false
                                              : true,
                                          keyboardType: TextInputType.number,
                                          decoration: InputDecoration(
                                            hintText:
                                                "Suhu Box (Dalam Celcius)",
                                            // label: "Petugas Penyerahan" ,
                                            labelText:
                                                "Suhu Box (Dalam Celcius)",
                                            border: OutlineInputBorder(
                                              borderRadius:
                                                  BorderRadius.circular(8),
                                            ),
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                // SUHU BOX BOTTOM END

                                if (getLocationStep.value ==
                                        getLocationStepEnum
                                            .catatanPengambilan ||
                                    getLocationStep.value ==
                                        getLocationStepEnum.catatanPengantaran)
                                  SizedBox(
                                    height: Constant.getActualY(
                                        context: context, y: 30),
                                  ),
                              ],
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
          ),
          if (getLocationLoading.value)
            const Opacity(
              opacity: 0.5,
              child: ModalBarrier(dismissible: false, color: Colors.black),
            ),
          if (getLocationLoading.value)
            const Center(
              child: CircularProgressIndicator(),
            ),
        ],
      ),
    );
  }

  Widget displayDetailText(BuildContext context, String teks, String value) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Expanded(
          child: Text(
            teks,
            style: Constant.body1(context: context).copyWith(
                fontWeight: FontWeight.w600, color: Constant.textPrimary),
          ),
        ),
        Expanded(
          child: Text(
            " : $value",
            maxLines: 2,
            overflow: TextOverflow.ellipsis,
            style: Constant.body1(context: context).copyWith(
                fontWeight: FontWeight.w600, color: Constant.textPrimary),
          ),
        )
      ],
    );
  }

  Widget headerCard(
      BuildContext context, Color bgColor, String teks, Color textColor) {
    return Container(
      height: Constant.getActualY(context: context, y: 44),
      decoration:
          BoxDecoration(color: bgColor, borderRadius: BorderRadius.circular(8)),
      child: Align(
        child: Text(
          teks,
          style: Constant.body1(context: context)
              .copyWith(fontWeight: FontWeight.w600, color: textColor),
        ),
      ),
    );
  }

  Widget cardDialogTundaTipe(
      context, String? tipe, Color bgColor, Color textColor) {
    return Expanded(
      flex: 5,
      child: Container(
        padding: EdgeInsets.symmetric(
          horizontal: Constant.getActualX(context: context, x: 3),
        ),
        decoration: BoxDecoration(
          color: bgColor,
          borderRadius: BorderRadius.circular(6),
        ),
        child: SizedBox(
          child: Text(
            tipe ?? "",
            style: TextStyle(
              color: textColor,
              fontSize: 10,
            ),
          ),
        ),
      ),
    );
  }

  // ADD WIDGET Hanya jika data.tipeId == 5
  List<Widget> pengambilanBahanInfo(
      BuildContext context,
      int? tipeId,
      TextEditingController jumlahPasienController,
      TextEditingController edtaRutinController,
      TextEditingController darahCitrasController,
      TextEditingController serumController,
      TextEditingController urineController,
      TextEditingController pleuraController,
      TextEditingController otherTextBahanController,
      TextEditingController totalOtherController,
      ValueNotifier<getLocationStepEnum> getLocationStep) {
    if (tipeId == 5) {
      return [
        SizedBox(
          height: Constant.getActualY(context: context, y: 20),
        ),
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: Text(
                "Info",
                style: Constant.body3(context: context).copyWith(
                    fontWeight: FontWeight.w400, color: Constant.textGrey),
              ),
            ),
          ],
        ),
        SizedBox(
          height: Constant.getActualY(context: context, y: 12),
        ),
        // Card Start
        SizedBox(
          width: double.infinity,
          child: Container(
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(color: Colors.grey, width: 0.1),
              boxShadow: [
                BoxShadow(
                    color: Color(0XFF919EAB).withOpacity(0.12),
                    offset: Offset(0.0, 12), //(x,y)
                    blurRadius: 24,
                    spreadRadius: -4),
                BoxShadow(
                  color: Color(0XFF919EAB).withOpacity(0.2),
                  offset: Offset(0.0, 0), //(x,y)
                  blurRadius: 2,
                ),
              ],
              borderRadius: BorderRadius.circular(12),
            ),
            padding: EdgeInsets.fromLTRB(
              Constant.getActualX(context: context, x: 12),
              Constant.getActualY(context: context, y: 24),
              Constant.getActualX(context: context, x: 12),
              Constant.getActualY(context: context, y: 24),
            ),
            child: Column(
              children: [
                // Jumlah Pasien
                Row(
                  children: [
                    Expanded(
                      child: TextFormField(
                        controller: jumlahPasienController,
                        enabled: (jumlahPasienController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "Jumlah Pasien",
                          // label: "Petugas Penyerahan" ,
                          labelText: "Jumlah Pasien",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                // EDTA Rutin
                Row(
                  children: [
                    Expanded(
                      child: TextFormField(
                        controller: edtaRutinController,
                        enabled: (edtaRutinController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "EDTA Rutin",
                          // label: "Petugas Penyerahan" ,
                          labelText: "EDTA Rutin",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                // Darah CITRAS
                Row(
                  children: [
                    Expanded(
                      child: TextFormField(
                        controller: darahCitrasController,
                        enabled: (darahCitrasController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "Darah CITRAS",
                          // label: "Petugas Penyerahan" ,
                          labelText: "Darah CITRAS",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                // SERUM
                Row(
                  children: [
                    Expanded(
                      child: TextFormField(
                        controller: serumController,
                        enabled: (serumController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "SERUM",
                          // label: "Petugas Penyerahan" ,
                          labelText: "SERUM",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                // URINE
                Row(
                  children: [
                    Expanded(
                      child: TextFormField(
                        controller: urineController,
                        enabled: (urineController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "URINE",
                          // label: "Petugas Penyerahan" ,
                          labelText: "URINE",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                // PLEURA
                Row(
                  children: [
                    Expanded(
                      child: TextFormField(
                        // textAlign: TextAlign.right,
                        controller: pleuraController,
                        enabled: (pleuraController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "PLEURA",
                          // label: "Petugas Penyerahan" ,
                          labelText: "PLEURA",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                // LAIN LAIN

                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Expanded(
                      child: Text(
                        "LAIN-LAIN",
                        style: Constant.body3(context: context).copyWith(
                            fontWeight: FontWeight.w400,
                            color: Constant.textBlack),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Expanded(
                      child: TextFormField(
                        controller: otherTextBahanController,
                        enabled: (otherTextBahanController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        maxLines: 4,
                        decoration: InputDecoration(
                          hintText: "",
                          // label: "Petugas Penyerahan" ,
                          labelText: "Jenis Bahan",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),

                SizedBox(
                  height: Constant.getActualY(context: context, y: 20),
                ),

                Row(
                  children: [
                    Expanded(
                      child: TextFormField(
                        controller: totalOtherController,
                        enabled: (totalOtherController.text.isEmpty ||
                                getLocationStep.value ==
                                    getLocationStepEnum.catatanPengambilan)
                            ? true
                            : false,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "Jumlah",
                          // label: "Petugas Penyerahan" ,
                          labelText: "Jumlah",
                          border: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(8),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ),
        // Card End
      ];
    } else {
      return [const SizedBox.shrink()];
    }
  }
}
