maheshj01 / searchfield

A highly customizable simple and easy to use flutter Widget to add a searchfield to your Flutter Application.This Widget allows you to search and select from list of suggestions.
MIT License
84 stars 64 forks source link

Expose onTapOutside-method of underlying TextFormField #94

Closed philitell closed 1 year ago

philitell commented 1 year ago

It would be really helpful if SearchField had a parameter onTapOutside. With this method SearchField could be used in complex Forms. An Implementation should be possible by exposing the onSaved-method of the underlying TextFormField inside SearchField.

Parameter definition:

/// Callback when a tap is performed outside Searchfield (during the time the field has focus)
final void Function(PointerDownEvent)? onTapOutside;

Implementation

    return CompositedTransformTarget(
      link: _layerLink,
      child: TextFormField(
        key: key,
        enabled: widget.enabled,
        autocorrect: widget.autoCorrect,
        readOnly: widget.readOnly,
        onFieldSubmitted: (x) {
          if (widget.onSubmit != null) {
            widget.onSubmit!(x);
          }
        },
        onTap: () {
          /// only call if SuggestionState = [Suggestion.expand]
          if (!isSuggestionExpanded && widget.suggestionState == Suggestion.expand) {
            suggestionStream.sink.add(widget.suggestions);
            if (mounted) {
              setState(() {
                isSuggestionExpanded = true;
              });
            }
          }
        },
        inputFormatters: widget.inputFormatters,
        controller: widget.controller ?? searchController,
        focusNode: _focus,
        validator: widget.validator,
        style: widget.searchStyle,
        textInputAction: widget.textInputAction,
        textCapitalization: widget.textCapitalization,
        keyboardType: widget.inputType,
        decoration:
            widget.searchInputDecoration?.copyWith(hintText: widget.hint) ?? InputDecoration(hintText: widget.hint),
        onSaved: widget.onSaved,
        onTapOutside: widget.onTapOutside,  //************ add this line****************

https://api.flutter.dev/flutter/material/TextField/onTapOutside.html This would also be very usefull.

maheshj01 commented 1 year ago

Closing as fixed in v0.8.8