// ignore_for_file: no_logic_in_create_state, must_be_immutable, depend_on_referenced_packages, non_constant_identifier_names, unnecessary_null_comparison

import 'package:chips_choice/chips_choice.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:general_package/constants/constants.dart';
import 'package:general_package/dynamic_form/src/view/dynamic_form_date_slider.dart';
import 'package:general_package/dynamic_form/src/view/dynamic_form_date_time_range.dart';
import 'package:general_package/dynamic_form/src/view/dynamic_form_image_upload.dart';
import 'package:general_package/dynamic_form/src/view/dynamic_form_otp.dart';
import 'package:general_package/dynamic_form/src/view/dynamic_form_rating.dart';
import 'package:general_package/dynamic_form/src/view/dynamic_form_tab.dart';
import 'package:general_package/dynamic_form/src/view/dynamic_form_value_add_service.dart';
import 'package:general_package/themes/themes.dart';
import 'package:general_package/dynamic_form/src/model/dynamic_form_model.dart';
import 'package:general_package/validator/validator.dart';
import 'package:intl/intl.dart';
import 'package:flutter/foundation.dart';
import '../model/dynamic_form_model.dart';
import 'dynamic_form_connectors.dart';
import 'dynamic_form_radio.dart';

class DynamicFormInput extends StatefulWidget {
  DynamicFormInput({super.key, required this.dynamicFormFieldModel});
  DynamicFormFieldModel dynamicFormFieldModel;

  static text(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderTextField(
              name: name,
              readOnly: readOnly,
              initialValue: initialValue,
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static email(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderTextField(
              autovalidateMode: AutovalidateMode.onUserInteraction,
              name: name,
              initialValue: initialValue,
              readOnly: readOnly,
              keyboardType: TextInputType.emailAddress,
              validator: (value) {
                if (EmailValidator.validate(value ?? "")) {
                  return "Error";
                } else {
                  return null;
                }
              },
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static phoneNumber(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderTextField(
              autovalidateMode: AutovalidateMode.onUserInteraction,
              name: name,
              initialValue: initialValue,
              keyboardType: TextInputType.phone,
              readOnly: readOnly,
              validator: (value) =>
                  PhoneNumberValidator().validateMobile(value!),
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static password(
    BuildContext context,
    String name,
    String? title,
    bool obscureText,
    bool visible,
    bool readOnly, {
    required Function onPressed,
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderTextField(
              autovalidateMode: AutovalidateMode.onUserInteraction,
              name: name,
              readOnly: readOnly,
              initialValue: initialValue,
              obscureText: obscureText,
              decoration: InputDecoration(
                  suffix: GestureDetector(
                    onTap: () => onPressed(),
                    child: Text(
                      obscureText ? "Show" : "Hide",
                      style: Theme.of(context)
                          .textTheme
                          .bodyText1!
                          .copyWith(color: AppTheme.primaryColor),
                    ),
                    // child: Icon(
                    //   obscureText
                    //       ? CupertinoIcons.eye_slash_fill
                    //       : CupertinoIcons.eye,
                    //   color: Colors.black,
                    //   size: 22.0,
                    // ),
                  ),
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static radio(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    required List<dynamic> options,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            FormBuilderRadioGroup(
              name: name,
              initialValue: initialValue,
              decoration: const InputDecoration(
                errorBorder: InputBorder.none,
                focusedErrorBorder: InputBorder.none,
                focusedBorder: InputBorder.none,
                enabledBorder: InputBorder.none,
              ),
              options: options
                  .map((option) => FormBuilderFieldOption(
                        value: option,
                        child: Text(
                          option.toString(),
                          style: Theme.of(context).textTheme.subtitle1,
                        ),
                      ))
                  .toList(growable: false),
            ),
          ],
        ),
      ),
    );
  }

  static radioModern(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    required List<dynamic> options,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: FormBuilderField(
        name: name,
        initialValue: initialValue,
        builder: (FormFieldState<dynamic> field) {
          // if (initialValue != null) {
          //   field.didChange(initialValue);
          // }
          return DynamicFormRadio(
            title: title,
            padding: padding,
            options: options,
            initialValue: initialValue,
            onChanged: (value) {
              field.didChange(value);
            },
          );
        },
      ),
    );
  }

  static dropdown(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    required List<dynamic> options,
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderDropdown<dynamic>(
              // autovalidate: true,
              name: name,
              initialValue: initialValue,
              borderRadius: BorderRadius.circular(20.0),
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
              items: options
                  .map((option) => DropdownMenuItem(
                        alignment: AlignmentDirectional.centerStart,
                        value: option,
                        child: Text(option),
                      ))
                  .toList(),
              valueTransformer: (val) => val?.toString(),
            ),
          ],
        ),
      ),
    );
  }

  static date(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    DateTime? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderDateTimePicker(
              name: name,
              initialEntryMode: DatePickerEntryMode.calendar,
              initialValue: initialValue ?? DateTime.now(),
              inputType: InputType.date,
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static time(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    DateTime? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderDateTimePicker(
              name: name,
              initialValue: initialValue ?? DateTime.now(),
              initialEntryMode: DatePickerEntryMode.calendar,
              inputType: InputType.time,
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static dateTime(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    DateTime? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderDateTimePicker(
              name: name,
              initialEntryMode: DatePickerEntryMode.calendar,
              initialValue: initialValue ?? DateTime.now(),
              inputType: InputType.both,
              format: DateFormat('dd-MM-yyyy hh:mm a'),
              firstDate: DateTime.now(),
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static dateRange(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    DateTimeRange? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderDateRangePicker(
              name: name,
              firstDate: DateTime.now(),
              lastDate: DateTime(2030),
              format: DateFormat('dd-MM-yyyy'),
              initialEntryMode: DatePickerEntryMode.calendar,
              initialValue: initialValue,
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static dateTimeRange(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    DateTimeRange? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: FormBuilderField(
        name: name,
        builder: (FormFieldState<dynamic> field) {
          return DynamicFormDateTimeRange(
            title: title,
            padding: padding,
            onChanged: (value) {
              field.didChange(value);
            },
          );
        },
      ),
    );
  }

  static rangeSlider(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    required double min,
    required double max,
    required RangeValues initialValue,
    required int divisions,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderRangeSlider(
              name: name,
              // onChanged: _onChanged,
              min: min,
              max: max,
              initialValue: initialValue,
              divisions: divisions,
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
            ),
          ],
        ),
      ),
    );
  }

  static switchInput(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    required bool initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            FormBuilderSwitch(
              title: Text(
                "$title",
                style: Theme.of(context).textTheme.bodyText1,
              ),
              name: name,
              initialValue: initialValue,
              decoration: InputDecoration(
                  filled: true,
                  fillColor: AppTheme.whiteColor,
                  contentPadding: GeneralConstants.instance.padding10,
                  errorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.redColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedErrorBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(width: 1, color: AppTheme.grayColor),
                    borderRadius: BorderRadius.circular(15.0),
                  ),
                  hintText: placeHolder),
              // onChanged: _onChanged,
            ),
          ],
        ),
      ),
    );
  }

  static checkbox(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    required List<dynamic> options,
    List<String>? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderCheckboxGroup(
              name: name,
              initialValue: initialValue,
              decoration: const InputDecoration(
                errorBorder: InputBorder.none,
                focusedErrorBorder: InputBorder.none,
                focusedBorder: InputBorder.none,
                enabledBorder: InputBorder.none,
              ),
              options: options
                  .map((option) => FormBuilderFieldOption(value: option))
                  .toList(growable: false),
            ),
          ],
        ),
      ),
    );
  }

  static segmented(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    required List<String> options,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            FormBuilderSegmentedControl(
              name: name,
              initialValue: initialValue,
              decoration: InputDecoration(
                  errorBorder: InputBorder.none,
                  focusedErrorBorder: InputBorder.none,
                  focusedBorder: InputBorder.none,
                  enabledBorder: InputBorder.none,
                  hintText: placeHolder),
              options: options
                  .map((option) => FormBuilderFieldOption(
                        value: option,
                        child: Text(
                          option.toString(),
                          style: const TextStyle(fontWeight: FontWeight.bold),
                        ),
                      ))
                  .toList(),
              // onChanged: _onChanged,
            ),
          ],
        ),
      ),
    );
  }

  static chipsSingle(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    required List<dynamic> options,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(children: [
          FormBuilderField<String?>(
            name: name,
            initialValue: initialValue,
            builder: (FormFieldState field) {
              return ChipsChoice<String>.single(
                wrapped: true,
                clipBehavior: Clip.antiAlias,
                value: field.value,
                onChanged: (value) {
                  field.didChange(value);
                },
                choiceStyle: C2ChipStyle.filled(
                  foregroundStyle: TextStyle(color: AppTheme.whiteColor),
                  color: AppTheme.grayColor,
                  borderRadius: const BorderRadius.all(
                    Radius.circular(25),
                  ),
                  selectedStyle: C2ChipStyle(
                    backgroundColor: AppTheme.primaryColor,
                    borderRadius: const BorderRadius.all(
                      Radius.circular(25),
                    ),
                  ),
                ),
                choiceItems: C2Choice.listFrom<String, dynamic>(
                  source: options,
                  value: (i, v) => v,
                  label: (i, v) => v,
                ),
              );
              // return CupertinoTextField(
              //     onChanged: (value) => field.didChange(value),
              //   );
            },
          ),
        ]),
      ),
    );
  }

  static chipsMultiple(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    List<String>? initialValue,
    required List<dynamic> options,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(children: [
          FormBuilderField<List<String>?>(
            name: name,
            initialValue: initialValue,
            builder: (FormFieldState field) {
              return ChipsChoice<String>.multiple(
                wrapped: true,
                clipBehavior: Clip.antiAlias,
                value: field.value ?? [],
                onChanged: (value) => field.didChange(value),
                choiceStyle: C2ChipStyle.filled(
                  foregroundStyle: TextStyle(color: AppTheme.whiteColor),
                  color: AppTheme.grayColor,
                  borderRadius: const BorderRadius.all(
                    Radius.circular(25),
                  ),
                  selectedStyle: C2ChipStyle(
                    backgroundColor: AppTheme.primaryColor,
                    borderRadius: const BorderRadius.all(
                      Radius.circular(25),
                    ),
                  ),
                ),
                choiceItems: C2Choice.listFrom<String, dynamic>(
                  source: options,
                  value: (i, v) => v,
                  label: (i, v) => v,
                ),
              );
              // return CupertinoTextField(
              //     onChanged: (value) => field.didChange(value),
              //   );
            },
          ),
        ]),
      ),
    );
  }

  static textArea(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
          padding: padding,
          child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                if(title!=null)Text(
                  title,
                  style: Theme.of(context).textTheme.bodyText1,
                ),
                const SizedBox(
                  height: 10,
                ),
                FormBuilderField<String?>(
                    name: name,
                    initialValue: initialValue,
                    builder: (FormFieldState field) {
                      return TextField(
                        controller: TextEditingController(text: field.value),
                        decoration: InputDecoration(
                            filled: true,
                            fillColor: AppTheme.whiteColor,
                            contentPadding: GeneralConstants.instance.padding10,
                            errorBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 1, color: AppTheme.redColor),
                              borderRadius: BorderRadius.circular(15.0),
                            ),
                            focusedErrorBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 1, color: AppTheme.grayColor),
                              borderRadius: BorderRadius.circular(15.0),
                            ),
                            focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 1, color: AppTheme.grayColor),
                              borderRadius: BorderRadius.circular(15.0),
                            ),
                            enabledBorder: OutlineInputBorder(
                              borderSide: BorderSide(
                                  width: 1, color: AppTheme.grayColor),
                              borderRadius: BorderRadius.circular(15.0),
                            ),
                            hintText: placeHolder),
                        keyboardType: TextInputType.multiline,
                        textInputAction: TextInputAction.done,
                        minLines: 2,
                        maxLines: 5,
                        onChanged: (value) => field.didChange(value),
                      );
                    })
              ])),
    );
  }

  static timeSlot(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            SizedBox(
              child: FormBuilderField<String?>(
                  name: name,
                  // initialValue: initialValue,
                  builder: (FormFieldState field) {
                    String? hours;
                    String? minutes;

                    if (initialValue != null) {
                      final initialValueList = initialValue.split(":");
                      if (initialValueList.isNotEmpty) {
                        hours = initialValueList[0];
                        minutes = initialValueList[1];
                      }
                    }
                    return Row(
                      children: [
                        Expanded(
                          flex: 2,
                          child: FormBuilderDropdown<String>(
                            // autovalidate: true,
                            name: "timeSlotHours$name",
                            initialValue: hours,
                            borderRadius: BorderRadius.circular(20.0),
                            onChanged: ((value) {
                              if (field.value != null) {
                                final fieldValueList = field.value!.split(":");
                                if (fieldValueList.isNotEmpty) {
                                  field
                                      .didChange("$value:${fieldValueList[1]}");
                                }
                              } else {
                                field.didChange("$value:");
                              }
                              print(field.value);
                            }),
                            decoration: InputDecoration(
                                filled: true,
                                fillColor: AppTheme.whiteColor,
                                contentPadding: GeneralConstants.instance.padding10,
                                errorBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.redColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                focusedErrorBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.grayColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                focusedBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.grayColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                enabledBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.grayColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                hintText: placeHolder),
                            items: List<DropdownMenuItem<String>>.generate(25,
                                (i) {
                              return DropdownMenuItem(
                                alignment: AlignmentDirectional.centerStart,
                                value: i.toString(),
                                child: Text(i.toString()),
                              );
                            }).toList(),
                            valueTransformer: (val) => val?.toString(),
                          ),
                        ),
                        Expanded(
                            child: Text(
                          "Hrs",
                          textAlign: TextAlign.center,
                          style: Theme.of(context).textTheme.bodyText1,
                        )),
                        Expanded(
                          flex: 2,
                          child: FormBuilderDropdown<String>(
                            // autovalidate: true,
                            name: "timeSlotMinutes$name",
                            initialValue: minutes,
                            borderRadius: BorderRadius.circular(20.0),
                            onChanged: ((value) {
                              if (field.value != null) {
                                final fieldValueList = field.value!.split(":");
                                if (fieldValueList.isNotEmpty) {
                                  field
                                      .didChange("${fieldValueList[0]}:$value");
                                }
                              } else {
                                field.didChange(":$value");
                              }
                              print(field.value);
                            }),
                            decoration: InputDecoration(
                                filled: true,
                                fillColor: AppTheme.whiteColor,
                                contentPadding: GeneralConstants.instance.padding10,
                                errorBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.redColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                focusedErrorBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.grayColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                focusedBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.grayColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                enabledBorder: OutlineInputBorder(
                                  borderSide: BorderSide(
                                      width: 1, color: AppTheme.grayColor),
                                  borderRadius: BorderRadius.circular(15.0),
                                ),
                                hintText: placeHolder),
                            items: List<DropdownMenuItem<String>>.generate(61,
                                (i) {
                              return DropdownMenuItem(
                                alignment: AlignmentDirectional.centerStart,
                                value: i.toString(),
                                child: Text(i.toString()),
                              );
                            }).toList(),
                            valueTransformer: (val) => val?.toString(),
                          ),
                        ),
                        Expanded(
                            child: Text(
                          "Mins",
                          textAlign: TextAlign.center,
                          style: Theme.of(context).textTheme.bodyText1,
                        )),
                        // const Text("Mins"),
                      ],
                    );
                  }),
            ),
          ],
        ),
      ),
    );
  }

  static tab(BuildContext context, String? title,
      {EdgeInsetsGeometry? padding,
      List<List<Widget>>? inputs,
      List<String>? tabsMenu}) {
    return DynamicFormTab(
      title: title!,
      inputs: inputs,
      tabsMenu: tabsMenu,
      padding: padding,
    );
  }

  static valueAddService(BuildContext context, String name, String? title,
      bool visible, bool readOnly,
      {EdgeInsetsGeometry? padding, List<ValueAddService>? options}) {
    return Visibility(
      visible: visible,
      child: DynamicFormValueAddService(
        name: name,
        title: title,
        padding: padding,
        options: options,
      ),
    );
  }  
  
  static connectors(BuildContext context, String name, String? title,
      bool visible, bool readOnly,
      {EdgeInsetsGeometry? padding, List<Connectors>? options}) {
    return Visibility(
      visible: visible,
      child: DynamicFormConnectors(
        name: name,
        title: title,
        padding: padding,
        options: options,
      ),
    );
  }

  static dateSlider(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    EdgeInsetsGeometry? padding,
    int? dateCount,
    DateTime? initialValue,
  }) {
    return Visibility(
      visible: visible,
      child: DynamicFormDateSlider(
        name: name,
        title: title,
        padding: padding,
        dateCount: dateCount??30,
        initialValue: initialValue,
      ),
    );
  }

  static otp(BuildContext context, String name, String? title, bool visible,
      bool readOnly, DynamicFormButtonModel dynamicFormButtonModel) {
    return Visibility(
      visible: visible,
      child: DynamicFormOTPWidget(
        dynamicFormButtonModel: dynamicFormButtonModel,
        name: name,
      ),
    );
  }

  static singleImageUpload(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    String? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: DynamicFormImageUpload(
        name: name,
        title: title,
        placeHolder: placeHolder,
        padding: padding,
        initialValue: initialValue,
      ),
    );
  }

  static multipleImageUpload(BuildContext context, String name, String? title,
      bool visible, bool readOnly,
      {String? placeHolder,
      String? initialValue,
      EdgeInsetsGeometry? padding,
      List<DynamicFormFieldModel>? dynamicFormModels}) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            Center(
              child: Wrap(
                  alignment: WrapAlignment.center,
                  runAlignment: WrapAlignment.center,
                  children: dynamicFormModels!.map((dynamic_form_model) {
                    return DynamicFormImageUpload(
                      name: dynamic_form_model.name,
                      title: dynamic_form_model.title,
                      placeHolder: dynamic_form_model.placeHolder,
                      padding: (dynamic_form_model.padding != null)
                          ? EdgeInsets.all(dynamic_form_model.padding!)
                          : null,
                      initialValue: dynamic_form_model.value,
                    );
                  }).toList()),
            ),
          ],
        ),
      ),
    );
  }

  static rating(
    BuildContext context,
    String name,
    String? title,
    bool visible,
    bool readOnly, {
    String? placeHolder,
    int? initialValue,
    EdgeInsetsGeometry? padding,
  }) {
    return Visibility(
      visible: visible,
      child: Container(
        padding: padding,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            if(title!=null)Text(
              title,
              style: Theme.of(context).textTheme.bodyText1,
            ),
            if(title!=null)const SizedBox(
              height: 10,
            ),
            SizedBox(
              child: FormBuilderField<int?>(
                  name: name,
                  initialValue: initialValue,
                  builder: (FormFieldState field) {
                    return DynamicFormRatingWidget(
                      field: field,
                      selectedRate: initialValue ?? 0,
                      onChanged: (count) => field.didChange(count),
                    );
                  }),
            ),
          ],
        ),
      ),
    );
  }

  @override
  State<DynamicFormInput> createState() => _DynamicFormInputState();
}

class _DynamicFormInputState extends State<DynamicFormInput> {
  bool _obscureTextPassword = true;
  @override
  void initState() {
    super.initState();
    if (widget.dynamicFormFieldModel.type==DynamicFormFieldTypeEnum.connectors) {
      print(DynamicFormFieldModel.toMap(widget.dynamicFormFieldModel));
    }
  }
  @override
  Widget build(BuildContext context) {
    Widget? formTypes(formType) {
      try {
        switch (formType) {
          case DynamicFormFieldTypeEnum.text:
            return DynamicFormInput.text(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.email:
            return DynamicFormInput.email(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.phoneNumber:
            return DynamicFormInput.phoneNumber(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.password:
            return DynamicFormInput.password(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              _obscureTextPassword,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              onPressed: () {
                setState(() {
                  _obscureTextPassword = !_obscureTextPassword;
                });
              },
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.date:
            return DynamicFormInput.date(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.time:
            return DynamicFormInput.time(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.dateTime:
            return DynamicFormInput.dateTime(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.dateRange:
            return DynamicFormInput.dateRange(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
              initialValue: widget.dynamicFormFieldModel.value,
            );
          case DynamicFormFieldTypeEnum.dateTimeRange:
            return DynamicFormInput.dateTimeRange(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
              initialValue: widget.dynamicFormFieldModel.value,
            );
          case DynamicFormFieldTypeEnum.switchInput:
            return DynamicFormInput.switchInput(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
              initialValue: widget.dynamicFormFieldModel.value ?? true,
            );
          case DynamicFormFieldTypeEnum.dropdown:
            return DynamicFormInput.dropdown(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              options: widget.dynamicFormFieldModel.option ?? [],
              initialValue: widget.dynamicFormFieldModel.value,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.radio:
            return DynamicFormInput.radio(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              options: widget.dynamicFormFieldModel.option ?? [],
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.radioModern:
            return DynamicFormInput.radioModern(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              options: widget.dynamicFormFieldModel.option ?? [],
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.checkbox:
            return DynamicFormInput.checkbox(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              options: widget.dynamicFormFieldModel.option ?? [],
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.chipsSingle:
            return DynamicFormInput.chipsSingle(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              options: widget.dynamicFormFieldModel.option ?? [],
              initialValue: widget.dynamicFormFieldModel.value,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.chipsMultiple:
            return DynamicFormInput.chipsMultiple(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              options: widget.dynamicFormFieldModel.option ?? [],
              initialValue: widget.dynamicFormFieldModel.value,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.segmented:
            return DynamicFormInput.segmented(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              options: (widget.dynamicFormFieldModel.option!=null)? widget.dynamicFormFieldModel.option!.cast<String>(): [],
              initialValue: widget.dynamicFormFieldModel.value,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.rangeSlider:
            return DynamicFormInput.rangeSlider(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
              divisions: widget.dynamicFormFieldModel.divisions!,
              initialValue: widget.dynamicFormFieldModel.value!,
              max: widget.dynamicFormFieldModel.max!,
              min: widget.dynamicFormFieldModel.min!,
            );
          case DynamicFormFieldTypeEnum.timeSlot:
            return DynamicFormInput.timeSlot(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.tab:
            return DynamicFormInput.tab(
                context, widget.dynamicFormFieldModel.title,
                padding: (widget.dynamicFormFieldModel.padding != null)
                    ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                    : null,
                inputs: widget.dynamicFormFieldModel.inputs!
                    .map((inputs) => inputs
                        .map((DynamicFormFieldInput) => DynamicFormInput(
                            dynamicFormFieldModel: DynamicFormFieldInput))
                        .toList())
                    .toList(),
                tabsMenu: widget.dynamicFormFieldModel.tabsMenu);
          case DynamicFormFieldTypeEnum.valueAddService:
            return DynamicFormInput.valueAddService(
                context,
                widget.dynamicFormFieldModel.name,
                widget.dynamicFormFieldModel.title,
                widget.dynamicFormFieldModel.visible,
                widget.dynamicFormFieldModel.readOnly,
                padding: (widget.dynamicFormFieldModel.padding != null)
                    ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                    : null,
                options: widget.dynamicFormFieldModel.valueAddService);
          case DynamicFormFieldTypeEnum.connectors:
            return DynamicFormInput.connectors(
                context,
                widget.dynamicFormFieldModel.name,
                widget.dynamicFormFieldModel.title,
                widget.dynamicFormFieldModel.visible,
                widget.dynamicFormFieldModel.readOnly,
                padding: (widget.dynamicFormFieldModel.padding != null)
                    ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                    : null,
                options: widget.dynamicFormFieldModel.connectors);
          case DynamicFormFieldTypeEnum.dateSlider:
          print(("dateSlider: ${widget.dynamicFormFieldModel.value}"));
            return DynamicFormInput.dateSlider(
                context,
                widget.dynamicFormFieldModel.name,
                widget.dynamicFormFieldModel.title,
                widget.dynamicFormFieldModel.visible,
                widget.dynamicFormFieldModel.readOnly,
                padding: (widget.dynamicFormFieldModel.padding != null)
                    ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                    : null,
                dateCount: widget.dynamicFormFieldModel.dateSliderCount,
                initialValue: (widget.dynamicFormFieldModel.value != null)
                    ? DateTime.parse(widget.dynamicFormFieldModel.value!.toString())
                    : null);
          case DynamicFormFieldTypeEnum.otp:
            return DynamicFormInput.otp(
                context,
                widget.dynamicFormFieldModel.name,
                widget.dynamicFormFieldModel.title,
                widget.dynamicFormFieldModel.visible,
                widget.dynamicFormFieldModel.readOnly,
                widget.dynamicFormFieldModel.resendOTPButton!);
          case DynamicFormFieldTypeEnum.singleImageUpload:
            return DynamicFormInput.singleImageUpload(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          case DynamicFormFieldTypeEnum.multipleImageUpload:
            return DynamicFormInput.multipleImageUpload(
                context,
                widget.dynamicFormFieldModel.name,
                widget.dynamicFormFieldModel.title,
                widget.dynamicFormFieldModel.visible,
                widget.dynamicFormFieldModel.readOnly,
                placeHolder: widget.dynamicFormFieldModel.placeHolder,
                initialValue: widget.dynamicFormFieldModel.value,
                padding: (widget.dynamicFormFieldModel.padding != null)
                    ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                    : null,
                dynamicFormModels: widget.dynamicFormFieldModel.filesUpload);
          case DynamicFormFieldTypeEnum.rating:
            return DynamicFormInput.rating(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
          default:
            return DynamicFormInput.text(
              context,
              widget.dynamicFormFieldModel.name,
              widget.dynamicFormFieldModel.title,
              widget.dynamicFormFieldModel.visible,
              widget.dynamicFormFieldModel.readOnly,
              placeHolder: widget.dynamicFormFieldModel.placeHolder,
              initialValue: widget.dynamicFormFieldModel.value,
              padding: (widget.dynamicFormFieldModel.padding != null)
                  ? EdgeInsets.all(widget.dynamicFormFieldModel.padding!)
                  : null,
            );
        }
      } catch (e) {
        if (kDebugMode) {
          debugPrint("$e - Error on formTypes()");
        }
      }
    }

    return Container(child: formTypes(widget.dynamicFormFieldModel.type));
  }
}
