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 63 forks source link

GestureDetector is not for SearchField #107

Closed vignesh235 closed 11 months ago

vignesh235 commented 12 months ago
        GestureDetector(
          onTap: () {
            print(
                "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
          },
          child: SearchField(
            controller: controller,
            searchInputDecoration: InputDecoration(
              labelText: label,
              labelStyle: const TextStyle(color: Colors.black),
              border: const OutlineInputBorder(
                  borderSide: BorderSide(color: Color(0x0ff2d2e4))),
              focusedBorder: const OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.black)),
            ),
            validator: (value) {
              if (value == null || value.isEmpty) {
                return errorMessage;
              }

              return null;
            },
            suggestions: suggestion
                .map((String) => SearchFieldListItem(String))
                .toList(),
            suggestionStyle: const TextStyle(fontSize: 16),
            suggestionState: Suggestion.expand,
            suggestionsDecoration: SuggestionDecoration(
                padding:
                    const EdgeInsets.only(top: 10.0, left: 5, bottom: 20),
                color: const Color(0xFFEDEFFE),
                borderRadius: const BorderRadius.all(Radius.circular(5))),
            textInputAction: TextInputAction.next,
            marginColor: const Color(0xFFEDEFFE),
            searchStyle: TextStyle(
              fontSize: 17,
              color: Colors.black.withOpacity(0.8),
            ),
            onSearchTextChanged: (p0) {
              searching.searchname(controller.text, doctype);
              return null;
            },
          ),
        ),
maheshj01 commented 12 months ago

Hello, @vignesh235, Thanks for filing the issue. Do you mean GestureDetector does not capture, Gestures captured on Searchfield?

btw, May I know what use case are you trying to achieve by wrapping Searchfield with Gesturedetector?

vignesh235 commented 12 months ago

@maheshmnj I want to call the API function while tap the search field and assign the value through the API function.

maheshj01 commented 11 months ago

@vignesh235, If I understand it right you want to call your API, when searchfield is tapped (meaning searchfield gains focus) is that correct?

Also, if you are trying to load the suggestions from API, In my opinion, suggestions should be loaded when the widget loads and not when the widget is interacted with.

If so have you tried using focusNode?

btw, I am afk to test your code what happens with the Gesture Detector? is the tap not triggered?

vignesh235 commented 11 months ago

Yes the tap is not triggered.

maheshj01 commented 11 months ago

@vignesh235 Exposed onTap method to SearchField which should help you with your use case.

Closing as fixed in v0.9.0

maheshj01 commented 11 months ago

@vignesh235 I have also added a sample example to load suggestions from network , please see the readme for sample code https://github.com/maheshmnj/searchfield