-
-
Notifications
You must be signed in to change notification settings - Fork 524
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
I am getting an error on the Type Ahead when I return a List<Entity> to the suggestionsCallback #21
Comments
I think this shows that the Kindly note that flutter_typeahead is a separate package maintained by another developer. Try raising the issue on this repo |
Would it be possible to implement this from the flutter_typeahead onSuggestionSelected: (suggestion) { |
I get your point @metaltigerfish. However, that would mean giving passing the
Which again seems to make sense. I'll explore the option, though the plan was not to significantly alter the underlying package |
Meanwhile might I suggest that you map your list of object to a list of strings, I've tried that and it seems to work. Your
|
Awesome thank you, I will try that . |
I'm gonna consider this elegant enough of a solution and close this issue since it doesn't directly relate to this package. |
@danvick I think your solution helps get rid of the error but inside of the code, we are still not be able to get the whole class object whose name is selected. I opened up an issue as you suggested in flutter_typeahead. Most of the time user will be getting the suggestions from a backend as objects and we would like to process the object(its id for instance) instead of just its .toString() version. Any help would be greatly appreciated. And thanks for this great package. |
I will consider working on the issue. The problem is that I've had this issue myself in other projects. My workaround for this issue was to use |
Thats a very interesting workaround @danvick i would love to see the code if possible. Because i have every other module in my form working other than this type ahead and i cant go forward without it. I use google places api to get suggestions. Everything in the form |
Try this out. Let me know if you have any questions. FormBuilderChipsInput(
decoration:
InputDecoration(labelText: "Contact Name"),
attribute: 'contact',
maxChips: 1, //Allow only one chip
valueTransformer: (val) => val?[0], //Pick the first element from the array
findSuggestions: (String query) async {
List<Contact> contacts = await _fetchContacts();
if (query.length != 0) {
var lowercaseQuery = query.toLowerCase();
return contacts.where((contact) {
return contact.name
.toLowerCase()
.contains(query.toLowerCase());
}).toList(growable: false)
..sort((a, b) => a.name
.toLowerCase()
.indexOf(lowercaseQuery)
.compareTo(b.name
.toLowerCase()
.indexOf(lowercaseQuery)));
} else {
return [];
}
},
chipBuilder: (context, state, contact) {
return InputChip(
key: ObjectKey(contact),
label: Text('${contact.name}'),
onDeleted: () => state.deleteChip(contact),
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
);
},
suggestionBuilder: (context, state, contact) {
return ListTile(
key: ObjectKey(contact),
title: Text('${contact.name}'),
subtitle: Text('${contact.email}'),
onTap: () => state.selectSuggestion(contact),
);
},
), |
This look very well and even better for my use case. Thanks @danvick :) However, one thing I could't get to work was constructing the initial suggestion list when query string is empty and the text box is pressed. I have a list of places which are around the users location and when the user presses the |
Within else {
return [];
} change it to: else {
return places;
} or whatever your equivalent of your code is. |
Thats how I have it at the moment but it doesn't show the initial suggestions when I touch and gain focus on the textinputview:/ It works only after I type a letter and then backspace. But it doesn't trigger in the beginning. Is there a way to fire |
@danvick Also some part of my suggestion list stays under the keyboard. Is there a way to limit it? Sorry for bothering you this much:/ EDIT: just realized this issue is not present with |
Since I'm the maintainer of |
I will do what you asked for in detail in a couple of hours when i am |
@danvick I have opened a pull request to allow control of the text to update onto TextEditingController. It has an assert statement to check if T is not of type String. Let me know if this works. |
Is it possible to use TypeAhead as an autocomplete textfield? It works great when an item from the list is selected. |
controls: [
FormBuilderInput.typeAhead(
label: 'Team 1',
attribute: 'team1',
require: true,
//value: team1name,
itemBuilder: (context, team1) {
return ListTile(
title: Text(team1.name),
);
},
suggestionsCallback: (query) async {
BlocProvider.of(context).dataBloc.typeAheadQuery.add(query);
return await BlocProvider.of(context)
.dataBloc
.typeAheadValues
.last;
},
),
],
The suggestions appear fine in the type ahead field suggestion box, but when I click on one of the items in the list I get the following error and the value does not get set to the selected value.
flutter: ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
flutter: The following assertion was thrown while handling a gesture:
flutter: type '_$Entity' is not a subtype of type 'String'
The text was updated successfully, but these errors were encountered: