Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to trigger by a / #100

Closed
lucasjinreal opened this issue Oct 12, 2023 · 10 comments
Closed

How to trigger by a / #100

lucasjinreal opened this issue Oct 12, 2023 · 10 comments
Labels
duplicate This issue or pull request already exists question Question on using a certain api of the package

Comments

@lucasjinreal
Copy link

lucasjinreal commented Oct 12, 2023

How to manually trigger search only by frist typing /, otherwise it can be used as normal text field?

@lucasjinreal lucasjinreal changed the title How to set list pop up at top of textfield? How to trigger by a / Oct 12, 2023
@maheshj01 maheshj01 added the in triage Issue is currently being triaged label Oct 13, 2023
@maheshj01
Copy link
Owner

Hello @lucasjinreal, Thanks for filing the issue. SearchField allows you to show suggestions based on custom logic using onSearchTextChanged callback. This callback is triggered everytime the text in searchfield changes. This callback expects you to return the filtered suggestions

I think you should be able to achieve it by doing something like this,

onSearchTextChanged: (query) {
      List<String> filter = [];
      if (query.startsWith('/')) {
        filter = suggestions;
      }
      return filter
          .map((e) => SearchFieldListItem<String>(e,
              child: Padding(
                padding: const EdgeInsets.symmetric(vertical: 4.0),
                child: Text(e,
                    style: TextStyle(fontSize: 24, color: Colors.red)),
              )))
          .toList();
          

Let me know if that doesn't work.

@maheshj01 maheshj01 added the waiting for author waiting for author to respond back with more info label Oct 13, 2023
@maheshj01
Copy link
Owner

You may also refer this complete code sample in the example app.

@lucasjinreal
Copy link
Author

lucasjinreal commented Oct 13, 2023

@maheshmnj thanks for your kindly demo.

the onSearchTextChanged's params query would be always whole text users input right? I want the pop window suggest only when first / pressed, if later more / typed, it will be ignored, will it handle this ?

if i want / triggered, and don't want it always trigger, I have to swipe the / when the suggested item clicked?

@maheshj01 maheshj01 added the question Question on using a certain api of the package label Oct 13, 2023
@maheshj01
Copy link
Owner

the onSearchTextChanged's params query would be always whole text users input right? I want the pop window suggest only when first / pressed, if later more / typed, it will be ignored, will it handle this ?

@lucasjinreal Yes, the query parameter gives the entire text present in the searchfield. That callback is invoked everytime the text input changes in the searchfield meaning if a user types / or // it will be triggered with respective text in the searchfield.

If you want to show suggestions only when text input has first / then you could write your own logic or also use regular expression. The callback only expects you to return a list (an empty list would mean no suggestions)

@lucasjinreal
Copy link
Author

@maheshmnj the query of this should be from textController right? So if i want it only detects / at first input, it should clear textController input right? which means, my ExtendedTextField (it shows span for certain text pattern) should not using span pattern start with /

@maheshj01 maheshj01 removed the waiting for author waiting for author to respond back with more info label Oct 13, 2023
@maheshj01
Copy link
Owner

the query of this should be from textController right? So if i want it only detects / at first input, it should clear textController input right?

I am just leveraging the onChanged property of the Flutter's TextField to get the query, But if you want more control on the searchfield input you can definetly use a TextEditingController and pass it to Searchfield.

https://github.com/maheshmnj/searchfield/blob/57e21c82ba24e1c7eb70fc105bba64306513abed/lib/src/searchfield.dart#L670-L675

Regarding positioning the suggestions on top of searchfield use the offset property

offset: Offset(0, -250),

@maheshj01 maheshj01 added the waiting for author waiting for author to respond back with more info label Oct 13, 2023
@lucasjinreal
Copy link
Author

@maheshmnj Hello, I have a customized TextField , how to using along with my customized TextField,
And seems it can not controlled by arrowUp key on Desktop.
I want using arrowUp key to select suggestions on Desktop.

@maheshj01
Copy link
Owner

maheshj01 commented Oct 17, 2023

@lucasjinreal At this point It is not possible to use your own textfield to get the searchfield features and there are no plans to do so in the future. May I know what customization you are referring to that is in Textfield but not in searchfield?

I want using arrowUp key to select suggestions on Desktop.

This is being tracked here #7

@maheshj01
Copy link
Owner

@lucasjinreal Keyboard support has been added to Searchfield, Now you should be able to navigate suggestions using the arrow keys, Please use the latest version 0.9.9

@maheshj01
Copy link
Owner

How to manually trigger search only by first typing /, otherwise it can be used as a normal text field.

@lucasjinreal I filed an issue to track trigger-based search where the search suggestion will be shown only when you enter a specific pattern. Please follow up on this issue #116

@maheshj01 maheshj01 added duplicate This issue or pull request already exists and removed waiting for author waiting for author to respond back with more info in triage Issue is currently being triaged labels Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists question Question on using a certain api of the package
Projects
None yet
Development

No branches or pull requests

2 participants