import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../../../../Controller/More/Locations/Addlocation/Addlocationcontroller.dart';
import '../../../../Helper/Constants/Colorconstants.dart';
import '../../../../Helper/custombutton.dart';
import '../../../../Model/Response/Tenantlocation/Getlocationbyidresponse.dart';

import '../../../../Helper/customederaction.dart';

class AddLocationView extends StatelessWidget {
  final bool editMode;
  final TenantLocationDetails? locationInfo;
  final int? chargeIndex;
   AddLocationView({super.key, required this.editMode, this.locationInfo, this.chargeIndex});

  AddLocationController addLocationController = Get.put(AddLocationController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AddLocationController>(
        initState: (_){
          addLocationController.editMode = editMode;
          print('AddLocationVieweditMode $editMode');
          addLocationController.locationInfo = locationInfo;
          print('initstatelocationName${ addLocationController.locationInfo?.locationname}');
          addLocationController.getAppLocations();
        },
        builder: (controller) {
          return Scaffold(
            backgroundColor: ColorConstants.lightColor,
            appBar: AppBar(
              elevation: 0.5,
              leading: InkWell(
                  onTap: () {
                    Navigator.pop(context);
                  },
                  child: Icon(
                    Icons.arrow_back,
                    color:  ColorConstants.secondaryColor,
                    size: 28,
                  )),
              titleSpacing: 1,
              title: Text('Add Location'),
              backgroundColor:  ColorConstants.primaryColor,
            ),
            body: ListView(
              padding: EdgeInsets.only(bottom: 60),
              children: [
                SizedBox(
                  height: 15,
                ),
                Column(
                  children: [
                    Container(
                      child: Padding(
                        padding: const EdgeInsets.only(
                          left: 6.0,
                          right: 6.0,
                          top: 3,
                        ),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            storeName(context),
                            SizedBox(
                              height: 12,
                            ),
                            email(context),
                            SizedBox(
                              height: 12,
                            ),
                            // contactNo(),
                            Container(
                              child: contactNo(context),
                              height: 55,
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.all(Radius.circular(7)),
                              ),
                            ),
                            SizedBox(
                              height: 12,
                            ),
                            // locationSheet(context ),
                            // SizedBox(
                            //   height: 12,
                            // ),
                            Padding(
                              padding: const EdgeInsets.all(5.0),
                              child: Row(
                                children: [
                                  Icon(
                                    Icons.location_on,
                                    color: ColorConstants.primaryColor,
                                  ),
                                  SizedBox(
                                    width: 8,
                                  ),
                                  Text(
                                    'Address',
                                    style: TextStyle(
                                        color: Colors.black54, fontSize: 18),
                                  ),
                                  Spacer(),
                                  controller.isEnterAddress == true
                                      ? InkWell(
                                    onTap: () {
                                      controller.isEnterAddress = false;
                                      controller.update();
                                    },
                                    child: Icon(
                                      Icons.check,
                                      color: Colors.grey[600],
                                      size: 21,
                                    ),
                                  )
                                      : InkWell(
                                    onTap: () {
                                      controller.isEnterAddress = true;
                                      controller.update();
                                    },
                                    child: Icon(
                                      Icons.close,
                                      color: Colors.grey[600],
                                      size: 21,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            SizedBox(height: 10,),
                            address(),
                            SizedBox(
                              height: 12,
                            ),
                            controller.isEnterAddress == true ? suburbField(context) : SizedBox(),
                            controller.isEnterAddress == true
                                ? SizedBox(
                              height: 12,
                            )
                                : SizedBox(),
                            controller.isEnterAddress == true ? cityField(context) : SizedBox(),
                            controller.isEnterAddress == true
                                ? SizedBox(
                              height: 10,
                            )
                                : SizedBox(),
                            controller.isEnterAddress == true ? stateField(context) : SizedBox(),
                            controller.isEnterAddress == true
                                ? SizedBox(
                              height: 12,
                            )
                                : SizedBox(),
                            pinCode(context),
                            SizedBox(
                              height: 12,
                            ),

                            // selectTime(),
                            // SizedBox(height: 12,),

                            // deliveryMinCard(),
                            // SizedBox(
                            //   height: 12,
                            // ),
                            // cancelTimeCard(),
                            //
                            // SizedBox(
                            //   height: 12,
                            // )
                          ],
                        ),
                      ),
                    ),
                  ],
                )
              ],
            ),
            bottomNavigationBar:SizedBox(
              height: Get.height*0.08,
              child:  Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Center(
                      child: Padding(
                        padding: const EdgeInsets.only(bottom: 11,top: 0),
                        child: RoundedButton(
                          onPressed: () {
                            addLocationController.describeValidation();
                          },
                          color:ColorConstants.primaryColor,
                          title: 'Submit',
                          controller: addLocationController.btnController,
                          textStyle: const TextStyle(
                              fontSize: 18,
                              fontFamily: "Lato",
                              color: Colors.white,
                              fontWeight: FontWeight.bold),
                          height: Get.height*0.06,
                          width: Get.width*0.8,
                        ),
                      )),
                ],
              ),

            ),
          );
        }
    );
  }

  Widget storeName(context) {
    return Container(
      decoration: BoxDecoration(
        color: ColorConstants.secondaryColor,
      ),
      child: TextFormField(
        textCapitalization: TextCapitalization.sentences,
        inputFormatters: <TextInputFormatter>[
          UpperCaseTextFormatter()
        ],
        decoration: CustomDecoration.textFieldStyle(
            labelTextStr: 'Store Name',
            prefixIcon: Icon(
              Icons.store,
              color: ColorConstants.primaryColor,
            )),
        controller: addLocationController.nameController,
        // focusNode: suburbNode,
        onEditingComplete: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
      ),
    );
  }

  Widget email(context) {
    return Container(
      decoration: BoxDecoration(
        color: ColorConstants.secondaryColor,
      ),
      child: Form(
        autovalidateMode: AutovalidateMode.always,
        child: TextFormField(
          validator: validateEmail,
          decoration: CustomDecoration.textFieldStyle(
              labelTextStr: 'Email',
              prefixIcon: Icon(
                Icons.email,
                color: ColorConstants.primaryColor,
              )),
          controller: addLocationController.emailController,
          // focusNode: suburbNode,
          onEditingComplete: () {
            FocusScope.of(context).requestFocus(FocusNode());
          },
        ),
      ),
    );
  }

  Widget contactNo(context) {
    return TextFormField(
      maxLength: 10,
      keyboardType:
      TextInputType.numberWithOptions(signed: true, decimal: true),
      controller: addLocationController.phoneNoController,
      textDirection: TextDirection.ltr,
      onChanged: (data){
        if(data.length==10){
          FocusScope.of(context).unfocus();
        }
      },
      onTap: () async {
        // print(_selectedDialogCountry.phoneCode);
        // currency();
      },
      decoration: InputDecoration(
        counterText: '',
        labelText: 'Contact no',
        labelStyle: TextStyle(color: Colors.grey),
        prefixIcon:Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Container(
              width: Get.width * 0.2,
              height: Get.height * 0.04,
              child: Row(
                children: [
                  Spacer(flex: 1,),
                  Flexible(
                    child: Icon(
                      Icons.phone_android_outlined,
                      color:  ColorConstants.primaryColor,
                    ),
                  ),
                  Spacer(flex: 1,),
                  Flexible(flex: 3,child: Text("+${addLocationController.selectedDialogCountry.phoneCode}",style: TextStyle(color:  ColorConstants.primaryColor,fontWeight: FontWeight.bold))),
                ],
              ),
            ),
          ],
        ),

        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(7.0),
          borderSide: BorderSide(
            color: Color.fromRGBO(220, 220, 220, 0.6),
            width: 2.0,
          ),
        ),
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(7.0),
          borderSide: BorderSide(
            color: Color.fromRGBO(220, 220, 220, 0.6),
            width: 2.0,
          ),
        ),
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(7.0),
          borderSide: BorderSide(
            color:  ColorConstants.primaryColor,
            width: 1.0,
          ),
        ),

      ),
    );
  }

  Widget locationSheet(context) {
    return InkWell(
      onTap: () {
        categorySheet(context);
      },
      child: Container(
        height: 60,
        // margin: EdgeInsets.symmetric(horizontal: 15),
        decoration: BoxDecoration(
            color: Colors.white,
            border: Border.all(color: Colors.grey[200]!, width: 2)),
        child: Padding(
          padding: const EdgeInsets.only(left: 10.0),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Icon(
                Icons.location_on,
                color:  ColorConstants.primaryColor,
              ),
              SizedBox(
                width: 10,
              ),
              Expanded(
                  flex: 8,
                  child: Text(
                      addLocationController.appLocationName == ''
                          ? "Select Location"
                          : addLocationController.appLocationName,
                      style: TextStyle(fontSize: 17, color: Colors.grey[500]))),
              Spacer(),
              Expanded(
                  flex: 1,
                  child: Icon(
                    Icons.arrow_drop_down,
                    color: Colors.grey[600],
                    size: 20,
                  ))
            ],
          ),
        ),
      ),
    );
  }

  categorySheet(context) {
    showModalBottomSheet(
        isDismissible: true,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
              topLeft: Radius.circular(15.0), topRight: Radius.circular(15)),
        ),
        context: context,
        builder: (builder) {
          return GetBuilder<AddLocationController>(
              builder: (controller) {
                return Container(
                    padding: const EdgeInsets.all(10),
                    child: Column(
                      children: [
                        SizedBox(
                          height: 40,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              const Text(
                                'Select Location',
                                style: TextStyle(fontSize: 16),
                              ),
                              GestureDetector(
                                child: Container(
                                  decoration: BoxDecoration(
                                      color:  ColorConstants.primaryColor,
                                      borderRadius: BorderRadius.circular(30)),
                                  child: const Padding(
                                    padding: EdgeInsets.symmetric(
                                        vertical: 5, horizontal: 10),
                                    child: Text(
                                      'Done',
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  ),
                                ),
                                onTap: () {
                                  Get.back();
                                },
                              )
                            ],
                          ),
                        ),
                        const SizedBox(
                          height: 10,
                        ),
                        Expanded(
                          child:controller.shimmer?Center(child: CircularProgressIndicator(color: ColorConstants.primaryColor)): GridView.builder(
                            itemCount:controller.locations.length,
                            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                                crossAxisCount: 3),
                            itemBuilder: (BuildContext context, int index) {
                              return Card(
                                child: GridTile(
                                  child: Stack(
                                    alignment: AlignmentDirectional.center,
                                    children: [
                                      GestureDetector(
                                        onTap: () {
                                          controller.appLocationId =controller.locations[index].applocationid??0;
                                          controller.appLocationName = controller.locations[index].city??'';

                                          Get.back();
                                          controller.update();
                                        },
                                        child: Column(
                                          mainAxisAlignment: MainAxisAlignment.center,
                                          children: [
                                            Image(
                                              image: NetworkImage(
                                                '${controller.locations[index].image}',
                                              ),
                                              fit: BoxFit.fitHeight,
                                              height: 70,
                                            ),
                                            const SizedBox(
                                              height: 10,
                                            ),
                                            Text('${controller.locations[index].city}'),
                                          ],
                                        ),
                                      ),
                                      Positioned(
                                        top: 0,
                                        right: 0,
                                        child: Icon(
                                          Icons.check_circle,
                                          color: controller.appLocationId == controller.locations[index].applocationid
                                              ? Colors.green
                                              : Colors.grey[300],
                                        ),
                                      )
                                    ],
                                  ), //just for testing, will fill with image later
                                ),
                              );
                            },
                          ),
                        )
                      ],
                    ));
              }
          );
        });
  }


  Widget address() {
    String text = '';
    int maxLength = 250;
    return Column(
      children: [
        TextFormField(
          maxLength: 150,
          onChanged: (text) => addLocationController.onSearchTextChanged(text),
          controller: addLocationController.addressController,
          maxLines: 3,
          cursorColor:  ColorConstants.primaryColor,
          style: TextStyle(
            color:  ColorConstants.textFieldColor,
            fontSize: 17,
          ),
          decoration: InputDecoration(
            fillColor:  ColorConstants.secondaryColor,
            counterText: '',
            filled: true,
            labelText: "Address",
            hintText: "",
            labelStyle: TextStyle(color: Colors.grey, fontSize: 18),
            hintStyle: TextStyle(color: Colors.grey,fontSize: 18),
            border: OutlineInputBorder(
              borderSide: BorderSide(
                color: Colors.black,
              ),
              borderRadius: BorderRadius.all(
                Radius.circular(7),
              ),
            ),
            focusedBorder: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(7)),
              borderSide: BorderSide(
                color:  ColorConstants.primaryColor,
              ),
            ),
            enabledBorder: OutlineInputBorder(
              borderRadius: BorderRadius.circular(7.0),
              borderSide: BorderSide(
                color: Color.fromRGBO(220, 220, 220, 0.6),
                width: 2.0,
              ),
            ),
          ),
        ),
        SizedBox(height: 8,),

        addLocationController.predictions.isNotEmpty?Container(
          height: Get.height*0.20,
          width: Get.width,
          padding: EdgeInsets.only(left: 5,right: 5),
          decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(10)),
          child: Obx(() {
            return ListView.builder(
              itemCount:  addLocationController.predictions.length,
              itemBuilder: (context, index) {
                final prediction =
                addLocationController.predictions[index]['description'];
                return ListTile(
                  title: Text(prediction),
                  onTap: () {
                    final placeId =
                    addLocationController.predictions[index]['place_id'];
                    addLocationController.getPlaceDetails(placeId,prediction);
                    FocusScope.of(context).unfocus();
                  },
                );
              },
            );

          }),):SizedBox()
      ],
    );
  }

  Widget suburbField(context) {
    return Container(
      decoration: BoxDecoration(
        color:  ColorConstants.secondaryColor,
      ),
      child: TextFormField(
        decoration: CustomDecoration.textFieldStyle(
            labelTextStr: 'Suburb',
            prefixIcon: Icon(
              Icons.location_city,
              color:  ColorConstants.primaryColor,
            )),
        controller:  addLocationController.suburbController,
        // focusNode: suburbNode,
        onEditingComplete: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
      ),
    );
  }

  Widget cityField(context) {
    return Container(
      decoration: BoxDecoration(
        color:  ColorConstants.secondaryColor,
      ),
      child: TextFormField(
        decoration: CustomDecoration.textFieldStyle(
            labelTextStr: 'City',
            prefixIcon: Icon(
              Icons.location_city,
              color:  ColorConstants.primaryColor,
            )),
        controller:  addLocationController.cityController,
        // focusNode: cityNode,
        onEditingComplete: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
      ),
    );
  }

  Widget stateField(context) {
    return Container(
      decoration: BoxDecoration(
        color:  ColorConstants.secondaryColor,
      ),
      child: TextFormField(
        decoration: CustomDecoration.textFieldStyle(
            labelTextStr: 'State',
            prefixIcon: Icon(
              Icons.location_city,
              color:  ColorConstants.primaryColor,
            )),
        controller:  addLocationController.stateController,
        // focusNode: stateNode,
        onEditingComplete: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
      ),
    );
  }

  Widget pinCode(context) {
    return Container(
      decoration: BoxDecoration(
        color:  ColorConstants.secondaryColor,
      ),
      child: TextFormField(
        decoration: CustomDecoration.textFieldStyle(
            labelTextStr: 'Pincode',
            prefixIcon: Icon(
              Icons.location_on,
              color:  ColorConstants.primaryColor,
            )),
        controller:  addLocationController.postalCodeController,
        // focusNode: postCodeNode,
        onEditingComplete: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
      ),
    );
  }

  Widget cancelTimeCard() {
    return GetBuilder<AddLocationController>(
        builder: (controller) {
          return Card(
              child: Container(
                margin: EdgeInsets.all(10),
                child: Column(
                  children: [
                    SizedBox(
                      height: 5,
                    ),
                    Row(
                      children: [
                        SizedBox(
                          width: 5,
                        ),
                        Text(
                          // "Delivery Minutes",
                          'Cancellation seconds',
                          style: TextStyle(color:  ColorConstants.primaryColor, fontSize: 18),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    const Text(
                      "Choose any one cancellation seconds",
                      // '${minDesc ?? ''}',
                      style: TextStyle(color: Colors.grey, fontSize: 17),
                    ),
                    const SizedBox(
                      height: 10,
                    ),
                    Row(
                      children: [
                        const SizedBox(
                          width: 5,
                        ),
                        Text(
                          // "Delivery Time :",
                          'Sec : ',
                          style: TextStyle(color: Colors.grey[900], fontSize: 15),
                        ),
                        const SizedBox(
                          width: 10,
                        ),
                        InkWell(
                          onTap: () {
                            controller.sec1 = true;
                            controller.sec2 = false;
                            controller.sec3 = false;
                            controller.cancellationSec = 20;
                            controller.update();

                          },
                          child: Container(
                            decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                color: controller.sec1 == true ?  ColorConstants.primaryColor : Colors.grey[100],
                                // borderRadius: BorderRadius.circular(70),
                                border: Border.all(color: Colors.grey)),
                            child: Padding(
                              padding: const EdgeInsets.all(10),
                              child: Center(
                                  child: Text(
                                    // '0 - 30',
                                    '20',
                                    style: TextStyle(
                                        fontWeight:
                                        controller.sec1 == true ? FontWeight.bold : FontWeight.w500,
                                        fontSize: 12,
                                        color:
                                        controller.sec1 == true ?  ColorConstants.secondaryColor : Colors.black45),
                                  )),
                            ),
                          ),
                        ),
                        SizedBox(
                          width: 20,
                        ),
                        InkWell(
                          onTap: () {
                            controller.sec1 = false;
                            controller.sec2 = true;
                            controller.sec3 = false;
                            controller.cancellationSec = 30;
                            controller.update();

                          },
                          child: Container(
                            decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                color: controller.sec2 == true ?  ColorConstants.primaryColor : Colors.grey[100],
                                // borderRadius: BorderRadius.circular(70),
                                border: Border.all(color: Colors.grey)),
                            child: Padding(
                              padding: const EdgeInsets.all(10),
                              child: Center(
                                  child: Text(
                                    // '30 - 60',
                                    '30',
                                    style: TextStyle(
                                        fontWeight:
                                        controller.sec2 == true ? FontWeight.bold : FontWeight.w500,
                                        fontSize: 12,
                                        color:
                                        controller.sec2 == true ?  ColorConstants.secondaryColor : Colors.black45),
                                  )),
                            ),
                          ),
                        ),
                        SizedBox(
                          width: 20,
                        ),
                        InkWell(
                          onTap: () {
                            controller.sec1 = false;
                            controller.sec2 = false;
                            controller.sec3 = true;
                            controller.cancellationSec = 40;
                            controller.update();
                          },
                          child: Container(
                            decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                color: controller.sec3 == true ?  ColorConstants.primaryColor : Colors.grey[100],
                                // borderRadius: BorderRadius.circular(70),
                                border: Border.all(color: Colors.grey)),
                            child: Padding(
                              padding: const EdgeInsets.all(10),
                              child: Center(
                                  child: Text(
                                    // '60 - 120',
                                    '40',
                                    style: TextStyle(
                                        fontWeight:
                                        controller.sec3 == true ? FontWeight.bold : FontWeight.w500,
                                        fontSize: 12,
                                        color:
                                        controller.sec3 == true ?  ColorConstants.secondaryColor : Colors.black45),
                                  )),
                            ),
                          ),
                        )
                      ],
                    ),
                    SizedBox(
                      height: 15,
                    )
                  ],
                ),
              ));
        }
    );
  }

  Widget deliveryMinCard() {
    return GetBuilder<AddLocationController>(
        builder: (controller) {
          return Card(
              child: Container(
                margin: EdgeInsets.all(10),
                child: Column(
                  children: [
                    SizedBox(
                      height: 5,
                    ),
                    Row(
                      children: [
                        SizedBox(
                          width: 5,
                        ),
                        Text(
                          // "Delivery Minutes",
                          'Preperation minuites',
                          style: TextStyle(color:  ColorConstants.primaryColor, fontSize: 18),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Text(
                      "Choose any one preperation Time",
                      // '${minDesc ?? ''}',
                      style: TextStyle(color: Colors.grey, fontSize: 17),
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    Row(
                      // mainAxisSize: MainAxisSize.max,
                      // mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        SizedBox(
                          width: 5,
                        ),
                        Text(
                          // "Delivery Time :",
                          'Min : ',
                          style: TextStyle(color: Colors.grey[900], fontSize: 15),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        InkWell(
                          onTap: () {
                            controller.min1 = true;
                            controller.min2 = false;
                            controller.min3 = false;
                            controller.deliveryMin = 30;
                            controller.update();

                          },
                          child: Container(
                            height: Get.height * 0.04,
                            width: Get.width * 0.165,
                            decoration: BoxDecoration(
                                shape: BoxShape.rectangle,
                                color: controller.min1 == true ?  ColorConstants.primaryColor : Colors.grey[100],
                                // borderRadius: BorderRadius.circular(70),
                                border: Border.all(color: Colors.grey)),
                            child: Padding(
                              padding: const EdgeInsets.only(left: 8, right: 8),
                              child: Center(
                                  child: Text(
                                    // '0 - 30',
                                    '${controller.min1Label ?? ''}',
                                    style: TextStyle(
                                        fontWeight:
                                        controller.min1 == true ? FontWeight.bold : FontWeight.w500,
                                        fontSize: 12,
                                        color:
                                        controller.min1 == true ?  ColorConstants.secondaryColor : Colors.black45),
                                  )),
                            ),
                          ),
                        ),
                        SizedBox(
                          width: 8,
                        ),
                        InkWell(
                          onTap: () {
                            controller.min1 = false;
                            controller.min2 = true;
                            controller.min3 = false;
                            controller.deliveryMin = 60;
                            controller.update();
                          },
                          child: Container(
                            height: Get.height * 0.04,
                            width: Get.width * 0.205,
                            decoration: BoxDecoration(
                                shape: BoxShape.rectangle,
                                color: controller.min2 == true ?  ColorConstants.primaryColor : Colors.grey[100],
                                // borderRadius: BorderRadius.circular(70),
                                border: Border.all(color: Colors.grey)),
                            child: Padding(
                              padding: const EdgeInsets.only(left: 8, right: 8),
                              child: Center(
                                  child: Text(
                                    // '30 - 60',
                                    '${controller.min2Label ?? ''}',
                                    style: TextStyle(
                                        fontWeight:
                                        controller.min2 == true ? FontWeight.bold : FontWeight.w500,
                                        fontSize: 12,
                                        color:
                                        controller.min2 == true ?  ColorConstants.secondaryColor : Colors.black45),
                                  )),
                            ),
                          ),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        InkWell(
                          onTap: () {
                            controller.min1 = false;
                            controller.min2 = false;
                            controller.min3 = true;
                            controller.deliveryMin = 120;
                            controller.update();


                          },
                          child: Container(
                            height: Get.height * 0.04,
                            width: Get.width * 0.205,
                            decoration: BoxDecoration(
                                shape: BoxShape.rectangle,
                                color: controller.min3 == true ?  ColorConstants.primaryColor : Colors.grey[100],
                                // borderRadius: BorderRadius.circular(70),
                                border: Border.all(color: Colors.grey)),
                            child: Padding(
                              padding: const EdgeInsets.only(left: 8, right: 8),
                              child: Center(
                                  child: Text(
                                    // '60 - 120',
                                    '${controller.min3Label ?? ''}',
                                    style: TextStyle(
                                        fontWeight:
                                        controller.min3 == true ? FontWeight.bold : FontWeight.w500,
                                        fontSize: 12,
                                        color:
                                        controller.min3 == true ?  ColorConstants.secondaryColor : Colors.black45),
                                  )),
                            ),
                          ),
                        )
                      ],
                    ),
                    SizedBox(
                      height: 15,
                    )
                  ],
                ),
              ));
        }
    );
  }

  String? validateEmail(String? value) {
    const pattern = r"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'"
        r'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-'
        r'\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*'
        r'[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4]'
        r'[0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9]'
        r'[0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\'
        r'x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])';
    final regex = RegExp(pattern);

    return value!.isNotEmpty && !regex.hasMatch(value)
        ? 'Enter a valid email address'
        : null;
  }

}

class UpperCaseTextFormatter extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
    return TextEditingValue(
      text: capitalize(newValue.text),
      selection: newValue.selection,
    );
  }
}
String capitalize(String value) {
  if(value.trim().isEmpty) return "";
  return "${value[0].toUpperCase()}${value.substring(1)}";
}