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 get selectedItems to be string instead of id in numbers #39

Closed
wasimakram3 opened this issue Jun 5, 2021 · 2 comments
Closed

Comments

@wasimakram3
Copy link

No description provided.

@lcuis
Copy link
Owner

lcuis commented Jun 5, 2021

A way to get the list of value Strings instead of the integer indexes is to map into a new variable like this:

List<String> selectedItemsInString=value.map<String>((index)=>items[index].value.toString()).toList();

Here is below the "Multi dialog" example with this new variable printed:

SearchChoices.multiple(
        items: items,
        selectedItems: selectedItemsMultiDialog,
        hint: Padding(
          padding: const EdgeInsets.all(12.0),
          child: Text("Select any"),
        ),
        searchHint: "Select any",
        onChanged: (value) {

          List<String> selectedItemsInString=value.map<String>((index)=>items[index].value.toString()).toList();
          selectedItemsInString.forEach((element) {
            print("selected: $element");
          });

          setState(() {
            selectedItemsMultiDialog = value;
          });
        },
        closeButton: (selectedItems) {
          return (selectedItems.isNotEmpty
              ? "Save ${selectedItems.length == 1 ? '"' + items[selectedItems.first].value.toString() + '"' : '(' + selectedItems.length.toString() + ')'}"
              : "Save without selection");
        },
        isExpanded: true,
      )

@lcuis
Copy link
Owner

lcuis commented Jun 20, 2021

Closing for inactivity. Feel free to reopen if needed.

@lcuis lcuis closed this as completed Jun 20, 2021
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

2 participants