ZetaPhoneInput constructor

ZetaPhoneInput({
  1. Key? key,
  2. bool? rounded,
  3. ValueChanged<PhoneNumber?>? onFieldSubmitted,
  4. FormFieldSetter<PhoneNumber>? onSaved,
  5. PhoneNumber? initialValue,
  6. FormFieldValidator<PhoneNumber>? validator,
  7. @Deprecated('Use onChange instead. ' 'Deprecated as of 0.15.0') ValueChanged<PhoneNumber?>? onChanged,
  8. ValueChanged<PhoneNumber?>? onChange,
  9. ZetaFormFieldRequirement? requirementLevel = ZetaFormFieldRequirement.none,
  10. String? label,
  11. @Deprecated('Use hintText instead. ' 'Deprecated as of 0.15.0') String? hint,
  12. String? hintText,
  13. @Deprecated('Use disabled instead. ' 'Deprecated as of 0.15.0') bool enabled = true,
  14. bool disabled = false,
  15. @Deprecated('Use errorText instead. ' 'Deprecated as of 0.15.0') bool hasError = false,
  16. String? errorText,
  17. @Deprecated('Use initialValue instead. ' 'Deprecated as of 0.15.0') String? initialCountry,
  18. List<String>? countries,
  19. ZetaWidgetSize size = ZetaWidgetSize.medium,
  20. @Deprecated('Set this as part of the initial value instead. ' 'Deprecated as of 0.15.0') String? countryDialCode,
  21. @Deprecated('Set this as part of the initial value instead. ' 'enabled is deprecated as of 0.15.0') String? phoneNumber,
  22. @Deprecated('Country search hint is deprecated as of 0.15.0') String? countrySearchHint,
  23. @Deprecated('Deprecated as of 0.15.0') bool? useRootNavigator,
  24. String? selectCountrySemanticLabel,
  25. AutovalidateMode? autovalidateMode,
})

Constructor for ZetaPhoneInput.

Implementation

ZetaPhoneInput({
  super.key,
  bool? rounded,
  super.onFieldSubmitted,
  super.onSaved,
  super.initialValue,
  super.validator,
  @Deprecated('Use onChange instead. ' 'Deprecated as of 0.15.0') ValueChanged<PhoneNumber?>? onChanged,
  super.onChange,
  super.requirementLevel = ZetaFormFieldRequirement.none,
  this.label,
  @Deprecated('Use hintText instead. ' 'Deprecated as of 0.15.0') String? hint,
  this.hintText,
  @Deprecated('Use disabled instead. ' 'Deprecated as of 0.15.0') bool enabled = true,
  super.disabled = false,
  @Deprecated('Use errorText instead. ' 'Deprecated as of 0.15.0') bool hasError = false,
  this.errorText,
  @Deprecated('Use initialValue instead. ' 'Deprecated as of 0.15.0') String? initialCountry,
  this.countries,
  this.size = ZetaWidgetSize.medium,
  @Deprecated('Set this as part of the initial value instead. ' 'Deprecated as of 0.15.0') String? countryDialCode,
  @Deprecated('Set this as part of the initial value instead. ' 'enabled is deprecated as of 0.15.0')
  String? phoneNumber,
  @Deprecated('Country search hint is deprecated as of 0.15.0') String? countrySearchHint,
  @Deprecated('Deprecated as of 0.15.0') bool? useRootNavigator,
  this.selectCountrySemanticLabel,
  super.autovalidateMode,
}) : super(
        builder: (field) {
          final _ZetaPhoneInputState state = field as _ZetaPhoneInputState;

          final colors = Zeta.of(field.context).colors;
          final spacing = Zeta.of(field.context).spacing;
          final newRounded = rounded ?? field.context.rounded;

          return InternalTextInput(
            label: label,
            hintText: hintText,
            errorText: field.errorText ?? errorText,
            size: size,
            controller: state.controller,
            requirementLevel: requirementLevel,
            rounded: rounded,
            disabled: disabled,
            focusNode: state._inputFocusNode,
            onSubmit: onFieldSubmitted != null ? (_) => onFieldSubmitted(field.value) : null,
            inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[\d\s\-]'))],
            keyboardType: TextInputType.phone,
            prefixText: state._selectedCountry.dialCode,
            borderRadius: BorderRadius.only(
              topRight: newRounded ? Radius.circular(spacing.minimum) : Radius.zero,
              bottomRight: newRounded ? Radius.circular(spacing.minimum) : Radius.zero,
            ),
            externalPrefix: ZetaDropdown(
              offset: Offset(0, spacing.medium),
              onChange: !disabled ? state.onDropdownChanged : null,
              value: state._selectedCountry.dialCode,
              onDismissed: state.onDropdownDismissed,
              items: state._dropdownItems,
              builder: (context, selectedItem, dropdowncontroller) {
                final borderSide = BorderSide(
                  color: disabled ? colors.borderDefault : colors.borderSubtle,
                );

                return GestureDetector(
                  onTap: !disabled ? dropdowncontroller.toggle : null,
                  child: Container(
                    constraints: BoxConstraints(
                      maxHeight: size == ZetaWidgetSize.large
                          ? Zeta.of(context).spacing.xl_8
                          : Zeta.of(context).spacing.xl_6,
                    ),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.only(
                        topLeft: newRounded ? Radius.circular(spacing.minimum) : Radius.zero,
                        bottomLeft: newRounded ? Radius.circular(spacing.minimum) : Radius.zero,
                      ),
                      border: Border(
                        left: borderSide,
                        top: borderSide,
                        bottom: borderSide,
                      ),
                      color: disabled ? colors.surfaceDisabled : colors.surfaceDefault,
                    ),
                    child: Column(
                      children: [
                        Expanded(
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            mainAxisSize: MainAxisSize.min,
                            children: [
                              Padding(
                                padding: EdgeInsets.only(
                                  left: spacing.medium,
                                  right: spacing.small,
                                ),
                                child: selectedItem?.icon,
                              ),
                              ZetaIcon(
                                !dropdowncontroller.isOpen ? ZetaIcons.expand_more : ZetaIcons.expand_less,
                                color: !disabled ? colors.iconDefault : colors.iconDisabled,
                                size: Zeta.of(context).spacing.xl,
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                );
              },
            ),
          );
        },
      );