flutter_smart_select
flutter_smart_select copied to clipboard
A S2SingleChanges<String> was used after being disposed.
when the value is set somewhere outside SmartSelect widget using setState, the S2Tile doesnt get redrawn. Forcing to redraw the widget by adding 'key' would result in error like mentioned in the subject.
SmartSelect<String>.single(
key: UniqueKey(),
title: 'Category',
value: categorySelected,```
@sonOfwidgets I tried this and it worked for me:
GlobalKey<S2State> collectionKey = GlobalKey<S2State>();
SmartSelect<String>.single(
key: collectionKey,
title: AppLocalizations.of(context)
.translate('page_product_filter_collection'),
placeholder: 'Choose one',
value: widget.filters['collection_id'],
onChange: (state) => setState(() => widget
.filters['collection_id'] = state.value.toString()),
choiceItems: [
for (var productCollection
in state.productCollections ?? [])
S2Choice(
value: productCollection.id.toString(),
title: productCollection.displayName,
),
],
modalFilter: true,
tileBuilder: (context, stateTile) {
return S2Tile.fromState(
stateTile,
isTwoLine: true,
isLoading: state.requestProductCollections,
padding: EdgeInsets.only(
left: 0, right: 0, top: 0, bottom: 0),
trailing: widget.filters['collection_id'] != null
? IconButton(
icon: Icon(Icons.close),
onPressed: () {
setState(() {
widget.filters['collection_id'] = null;
collectionKey = GlobalKey<S2State>();
});
},
)
: IconButton(
icon: Icon(Icons.keyboard_arrow_right),
onPressed: null),
);
},
);
@sonOfwidgets I tried this and it worked for me:
GlobalKey<S2State> collectionKey = GlobalKey<S2State>(); SmartSelect<String>.single( key: collectionKey, title: AppLocalizations.of(context) .translate('page_product_filter_collection'), placeholder: 'Choose one', value: widget.filters['collection_id'], onChange: (state) => setState(() => widget .filters['collection_id'] = state.value.toString()), choiceItems: [ for (var productCollection in state.productCollections ?? []) S2Choice( value: productCollection.id.toString(), title: productCollection.displayName, ), ], modalFilter: true, tileBuilder: (context, stateTile) { return S2Tile.fromState( stateTile, isTwoLine: true, isLoading: state.requestProductCollections, padding: EdgeInsets.only( left: 0, right: 0, top: 0, bottom: 0), trailing: widget.filters['collection_id'] != null ? IconButton( icon: Icon(Icons.close), onPressed: () { setState(() { widget.filters['collection_id'] = null; collectionKey = GlobalKey<S2State>(); }); }, ) : IconButton( icon: Icon(Icons.keyboard_arrow_right), onPressed: null), ); }, );
It does not work for me
Anyone know how to fix this ?
Could you remove UniqueKey and try again. I have faced same issue and solved with remove UniqueKey.
i tried every solution above, still no luck.
if setState is called outside SmartSelect, then error goes away.
But the main goal is to 'setState' as soon as user select other option/chip.
Anyone know how to fix this ? What can i do to reset the selection?
Anyone know how to fix this ? What can i do to reset the selection?
I solved this problem by interfering with the library. This works for me. I took the set code of the library and wrapped it with the GetStorage block. In this way, I would be able to trigger my code from the outside. (You can use something else to trigger it. It will probably work.) The main reason I'm doing this here is that setState cannot interfere with the library from outside. I added the set initial default value part.
Here, I have run my code by triggering it under any method.
Here, my process only works for a single selection. For multi-select, you need to add the set code under the multi-select initState in the same way. Otherwise it only works for single selection. Good job everyone, hope it works for you.
I released https://pub.dev/packages/flutter_awesome_select with fixed null safety. Could you check that everything works for you?
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.