-
Notifications
You must be signed in to change notification settings - Fork 117
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
Either zero or 2 or more items were detected with the same value, and if the first item is not selected the other selections disappear from the button #138
Comments
Hello @Gendows ! For your question at SO, you should use value: selectedTypeID.isEmpty ? null : selectedTypeID.last If you want to use custom class as your value, you'll need to override operator == & hashCode to make your class immutable (comparable), or maybe use a package like Equatable/Freezed to easily achieve same thing. |
I am already using the id not the title . See the code provided... :) |
For the snippet above, you're using value: selectedTypes.isEmpty ? null : selectedTypes.last.id, |
There is no id in selectedTypes it only stores one value [client, contractor, ...etc] And i'm not currently using any classes on this code |
Oh sorry the multiple questions confused me. |
Sorry for confusing you while explaining No. The other two are the issue now. The main points are the button only shows selected item when the first one is selected Displaying selected items text instead of value on button Search by at items text not the id |
To start with, you need to use your custom class as your |
There is no custom class 😕 I retrieve the list from firestore by stream builder |
If you want you can use TeamViewer or anydisk app to view and debug the code yourself |
I'm talking about this. You can do: items: snapshot.data!.docs.map((DocumentSnapshot item) {
final SomeItem item = SomeItem(id: item.id, title: item.get('title')); and You can ofc use separated lists for |
if that will work it will be better, this is the custom class i used before which gave me the error (zero or two or more...)
|
i will add override string to my class as
|
because you need to override ==/hashCode, add this to your @override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is ConTyp &&
(identical(other.id, id) || other.id == id) &&
(identical(other.title, title) || other.title == title));
}
@override
int get hashCode => Object.hash(runtimeType, id, title); Then: Your list will be like: Your Your searchMatchFn: (item, searchValue) {
return (item.value.title.contains(searchValue));
}, |
Added by mistake, delete that line. |
The code you posted doesn't have your Also, no need for screenshots + unrelated widgets code |
sorry, copied the wrong file Class File
Widget file
print(selectedTypes) list as i tap on items (see duplications of client item)
|
fixed by changing |
Alright! :) |
thank you for your help, you made my day 💯 🥇 |
hello Eng, Ahmed, it's cheerful to know that you are from Egypt too :)
I'm using your package to add multiselect to the dropdownbutton i have on code below,
What i'm trying to achieve
![image](https://user-images.githubusercontent.com/1626099/229243127-e61b9c04-0345-46e9-85f6-ca189a6e5b83.png)
displaying contact types from firestore to categories company contacts
every type has a title (which it can be changed to Multilanguage's titles) and a cons id in english (not changeable).
i want to display the title in drop down menu and store the selected ID's in a list.
tried custom class with two strings (id, title) but storing the value as (id, title) wasn't successful with his error every time for giving more than value (id, title) as item's value Stack Overflow post
items.where((DropdownMenuItem<T> item) { return item.value == value; }).length == 1': There should be exactly one item with [DropdownButton]'s value: عميل. Either zero or 2 or more [DropdownMenuItem]s were detected with the same value)
as a work around I'm trying to store only values in a selected list and only displaying it's title on the button, after that on profile page or whatever will search for the title on firestore collection via it's id
but even there are some issues if the first item is selected it's displaying the selected items, but if not, there is an error
Exception caught by rendering library: 'package:flutter/src/rendering/stack.dart': Failed assertion: line 749 pos 12: 'child != null': is not true.
or
Exception caught by rendering library: 'package:flutter/src/rendering/stack.dart': Failed assertion: line 748 pos 12: 'i == index': is not true.
and the id's are shown on the button, how can i change them to the title instead of the
![2](https://user-images.githubusercontent.com/1626099/229242230-c2f446e4-5571-4240-8c30-dd9f8d5b54b0.jpg)
![3](https://user-images.githubusercontent.com/1626099/229242276-cb09ba4f-1324-4445-9278-177c5864869a.jpg)
![4](https://user-images.githubusercontent.com/1626099/229242280-1899ca6e-25fa-4e59-9d72-cfced93c3478.jpg)
(item value)?
some screens from the app
other thing how can i define the (title) value instead of item value for search fn? because it searching for the id not the displaying items title
![5](https://user-images.githubusercontent.com/1626099/229244951-709a8ad3-b323-4584-a09d-722044c4582c.jpg)
![6](https://user-images.githubusercontent.com/1626099/229244956-a0cf18e2-c685-4bc4-a88f-b80600f30303.jpg)
full code:
`
`
The text was updated successfully, but these errors were encountered: