ZetaSearchBar constructor

ZetaSearchBar({
  1. AutovalidateMode? autovalidateMode,
  2. FormFieldValidator<String>? validator,
  3. FormFieldSetter<String>? onSaved,
  4. ValueChanged<String?>? onChange,
  5. @Deprecated('Use onFieldSubmitted instead. ' 'deprecated as of 0.15.0') ValueChanged<String?>? onSubmit,
  6. ValueChanged<String?>? onFieldSubmitted,
  7. ZetaFormFieldRequirement? requirementLevel,
  8. TextEditingController? controller,
  9. bool disabled = false,
  10. String? initialValue,
  11. ZetaWidgetSize size = ZetaWidgetSize.medium,
  12. ZetaWidgetBorder shape = ZetaWidgetBorder.rounded,
  13. @Deprecated('hint has been removed. ' 'deprecated as of 0.15.0') String? hint,
  14. @Deprecated('Use placeholder instead. ' 'deprecated as of 0.16.0') String? hintText,
  15. String? placeholder,
  16. Future<String?> onSpeechToText()?,
  17. bool showSpeechToText = true,
  18. @Deprecated('Use disabled instead. ' 'enabled is deprecated as of 0.11.0') bool enabled = true,
  19. FocusNode? focusNode,
  20. TextInputAction? textInputAction,
  21. String? microphoneSemanticLabel,
  22. String? clearSemanticLabel,
  23. Key? key,
  24. @Deprecated('Show leading icon is deprecated as of 0.14.2') bool showLeadingIcon = true,
  25. @Deprecated('Use onChange instead') ValueChanged<String?>? onChanged,
})

Constructor for ZetaSearchBar.

Implementation

ZetaSearchBar({
  super.autovalidateMode,
  super.validator,
  super.onSaved,
  super.onChange,
  @Deprecated('Use onFieldSubmitted instead. ' 'deprecated as of 0.15.0') ValueChanged<String?>? onSubmit,
  super.onFieldSubmitted,
  super.requirementLevel,
  super.controller,
  super.disabled = false,
  super.initialValue,
  this.size = ZetaWidgetSize.medium,
  this.shape = ZetaWidgetBorder.rounded,
  @Deprecated('hint has been removed. ' 'deprecated as of 0.15.0') String? hint,
  @Deprecated('Use placeholder instead. ' 'deprecated as of 0.16.0') String? hintText,
  this.placeholder,
  this.onSpeechToText,
  this.showSpeechToText = true,
  @Deprecated('Use disabled instead. ' 'enabled is deprecated as of 0.11.0') bool enabled = true,
  this.focusNode,
  this.textInputAction,
  this.microphoneSemanticLabel,
  this.clearSemanticLabel,
  super.key,
  @Deprecated('Show leading icon is deprecated as of 0.14.2') bool showLeadingIcon = true,
  @Deprecated('Use onChange instead') ValueChanged<String?>? onChanged,
}) : super(
        builder: (field) {
          final zeta = Zeta.of(field.context);

          final _ZetaSearchBarState state = field as _ZetaSearchBarState;

          final BorderRadius borderRadius = switch (shape) {
            ZetaWidgetBorder.rounded => zeta.radius.minimal,
            ZetaWidgetBorder.full => zeta.radius.full,
            _ => zeta.radius.none,
          };

          late final double iconSize;

          switch (size) {
            case ZetaWidgetSize.large:
              iconSize = zeta.spacing.xl_2;
            case ZetaWidgetSize.medium:
              iconSize = zeta.spacing.xl;
            case ZetaWidgetSize.small:
              iconSize = zeta.spacing.large;
          }

          return ZetaRoundedScope(
            rounded: shape != ZetaWidgetBorder.sharp,
            child: Semantics(
              excludeSemantics: disabled,
              label: disabled ? placeholder ?? 'Search' : null, // TODO(UX-1003): Localize
              enabled: disabled ? false : null,
              child: InternalTextInput(
                focusNode: focusNode,
                size: size,
                disabled: disabled,
                constrained: true,
                borderRadius: borderRadius,
                controller: state.effectiveController,
                keyboardType: TextInputType.text,
                textInputAction: textInputAction,
                placeholder: placeholder ?? 'Search', // TODO(UX-1003): Localize
                onSubmit: onFieldSubmitted,
                onChange: state.onChange,
                prefix: ZetaIcon(
                  ZetaIcons.search,
                  color: !disabled ? zeta.colors.iconSubtle : zeta.colors.iconDisabled,
                  size: iconSize,
                ),
                suffix: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    if (state.effectiveController.text.isNotEmpty && !disabled) ...[
                      InputIconButton(
                        icon: ZetaIcons.cancel,
                        onTap: () => state.onChange(''),
                        disabled: disabled,
                        size: size,
                        semanticLabel: clearSemanticLabel,
                        color: zeta.colors.iconSubtle,
                        key: const ValueKey('search-clear-btn'),
                      ),
                      if (showSpeechToText)
                        SizedBox(
                          height: iconSize,
                          child: VerticalDivider(
                            color: zeta.colors.cool.shade40,
                            width: 5,
                            thickness: 1,
                          ),
                        ),
                    ],
                    if (showSpeechToText)
                      InputIconButton(
                        icon: ZetaIcons.microphone,
                        onTap: state.onSpeechToText,
                        key: const ValueKey('speech-to-text-btn'),
                        disabled: disabled,
                        semanticLabel: microphoneSemanticLabel,
                        size: size,
                        color: zeta.colors.iconDefault,
                      ),
                  ],
                ),
              ),
            ),
          );
        },
      );