flutter_smart_select icon indicating copy to clipboard operation
flutter_smart_select copied to clipboard

Select/de-select programatically

Open xuala69 opened this issue 3 years ago • 7 comments

I'm unable to find any feature that lets me select/deselect items programatically. Use case would be , a user selects an item from one page and navigates to another where he can edit his selection. I would like the previously selected option to be marked as selected on the edit page.

I've tried setting the selected value to true but it's not doing anything. My code is as below

choiceOptions.add( S2Choice<String>( value: choiceOptions.length.toString(), title: _service.name, selected: true, ), );

xuala69 avatar Jan 15 '21 09:01 xuala69

Me to... I'm even setting the current item that I'm observing on my screen... And nothing seems to work, I don't know what to do now

Katekko avatar Jan 20 '21 16:01 Katekko

I need to clear all the selected choices on a button tap. Changing value to [] doesn't clear the selected chips.

SmartSelect<String>.multiple(
              ...,
              value: filter.reasons, // where filter.values is [] after taping a clear button.
              ...,
)

Galti avatar Jan 21 '21 10:01 Galti

I have the same problem, does anyone know the solution?

ffamar avatar Feb 11 '21 18:02 ffamar

Is there anyone with the solution to this problem?

ffamar avatar Feb 22 '21 10:02 ffamar

Here is my solution to react on value changes programmatically :

SmartSelect<String>.single(
  // ...
  value : < here the value you change programmatically elsewhere >
)

I have added the following method to the file widget.dart in the class S2SingleState<T>

  @override
  void didUpdateWidget(SmartSelect<T> oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (widget.singleValue != oldWidget.singleValue) {
      setState(() => value = widget.singleValue);
      // I don't think it is needed here but if you need it, uncomment the following line to return state to onChange callback
     // onChange?.call(this);
    }
  }

The same modifications must be done on SmartSelect<T>.multiple if it is your case.

sperochon avatar Mar 20 '21 09:03 sperochon

same issue here

kendall-lu avatar May 19 '21 19:05 kendall-lu

I released https://pub.dev/packages/flutter_awesome_select with fixed null safety. Could you check that everything works for you?

vasilich6107 avatar Nov 12 '21 23:11 vasilich6107

Hi everyone,

I'm really sorry for not maintaining the smart_select package in a long time. It's been a great project, but it's become too difficult for me to maintain, especially since I've been going through a tough time for the past few years.

In its place, I've released a new package called choice. The combination to smart_select and chips_choice with cleaner, more flexible, and composable API for creating inline or prompted choice widgets with single or multiple selection.

I hope you'll check out choice. I think you'll find it to be a great replacement for smart_select.

Thanks for your understanding.

davigmacode avatar Aug 26 '23 11:08 davigmacode