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

Dynamic data #77

Closed
sajjadjaved01 opened this issue Apr 27, 2020 · 6 comments
Closed

Dynamic data #77

sajjadjaved01 opened this issue Apr 27, 2020 · 6 comments

Comments

@sajjadjaved01
Copy link

sajjadjaved01 commented Apr 27, 2020

Hi there.
I'm fetching a list of Users from API, i have debugged every thing, data is good.
The issue is i'm unable to show suggestions.

Mean while i can able to do that with static data, the suggestions are showing, but with API data filtering is working on that data, but suggestions list not showing.
Any Idea..

AutoCompleteTextField<UserDataModel>( key: key, clearOnSubmit: false, suggestions: usersList, style: TextStyle(color: Colors.white70), decoration: InputDecoration( hintText: 'Search Here', contentPadding: EdgeInsets.only(left: 10.2, top: 15.0), border: InputBorder.none, hintStyle: TextStyle(color: Colors.white70), suffixIcon: IconButton( iconSize: 30.0, color: Colors.white70, icon: Icon(Icons.search), onPressed: () {}, ), ), itemFilter: (item, query) { print(item.name); return item.name .toLowerCase() .contains(query.toLowerCase()); }, itemSorter: (a, b) { return a.name.compareTo(b.name); }, itemSubmitted: (item) { setState(() { searchTextField.textField.controller.text = item.name; }); }, itemBuilder: (context, item) { return row(item); }, ),

@Arkasher
Copy link

I'm having the same problem. Any suggestions?

@sajjadjaved01
Copy link
Author

still figuring this ...

@Arkasher
Copy link

I got it. You should update the Widget and call the setState.

Like:
setState(() { autoCompleteTextField = updateField(); });

I put this in the textChanged listener, after receive the response from back-end.

@sajjadjaved01
Copy link
Author

what is updateField() for @Arkasher
can you please explain, it a little further.

@Arkasher
Copy link

updateField is the method that will return a new instance of the autoCompleteTextField. The setState is called after you update the suggestions list.

@YannicAmir
Copy link

I got it. You should update the Widget and call the setState.

Like:
setState(() { autoCompleteTextField = updateField(); });

I put this in the textChanged listener, after receive the response from back-end.

@Arkasher if you don't mind showing me a full code example of your suggested implementation for fetching data dynamic from API and using autocomplete, I would really appreciate it! I'm facing this issue now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants