ZetaSearchBar constructor
- AutovalidateMode? autovalidateMode,
- FormFieldValidator<
String> ? validator, - FormFieldSetter<
String> ? onSaved, - ValueChanged<
String?> ? onChange, - @Deprecated('Use onFieldSubmitted instead. ' 'deprecated as of 0.15.0') ValueChanged<
String?> ? onSubmit, - ValueChanged<
String?> ? onFieldSubmitted, - ZetaFormFieldRequirement? requirementLevel,
- TextEditingController? controller,
- bool disabled = false,
- String? initialValue,
- ZetaWidgetSize size = ZetaWidgetSize.medium,
- ZetaWidgetBorder 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,
- String? placeholder,
- Future<
String?> onSpeechToText()?, - bool showSpeechToText = true,
- @Deprecated('Use disabled instead. ' 'enabled is deprecated as of 0.11.0') bool enabled = true,
- FocusNode? focusNode,
- TextInputAction? textInputAction,
- String? microphoneSemanticLabel,
- String? clearSemanticLabel,
- Key? key,
- @Deprecated('Show leading icon is deprecated as of 0.14.2') bool showLeadingIcon = true,
- @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,
),
],
),
),
),
);
},
);