I'm trying to select a value in a dropdown menu and transfer that value to the dropdown menu title when it closes, but an error message appears when I try to do this, but the value does appear in the dropdown menu title:
Unhandled Exception: A S2SingleSelection was used after being disposed. Once you have called dispose() on a S2SingleSelection, it can no longer be used.
I don't understand at any point I use S2SingleSelection.
Package used: https://pub.dev/packages/awesome_select version 6.0.0
Here is my code and the initial value:
String? _selectedLevel;
final firestore = FirebaseFirestore.instance;
SmartSelect.single(
selectedValue: _selectedLevel,
onChange: (newValue) {
setState(() {
_selectedLevel = newValue.value;
});
},
choiceItems: documents.map((DocumentSnapshot<dynamic> dataDoc) {
return S2Choice(
value: dataDoc.data()['field1'],
title: dataDoc.data()['field1'],
);
}).toList(),
placeholder: 'N/A',
tileBuilder: (context, value) {
return Container(
padding: EdgeInsets.symmetric(
vertical: MediaQuery.of(context).size.height * 0.01,
horizontal: MediaQuery.of(context).size.width * 0.03,
),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.onPrimary,
borderRadius: BorderRadius.circular(20),
),
child: Row(
children: [
Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width * 0.035,
),
child: Icon(
FontAwesomeIcons.locationDot,
color: Theme.of(context).colorScheme.primary,
size: MediaQuery.of(context).size.width * 0.065,
),
),
Expanded(
child: S2Tile(
value: Text(
_selectedLevel != null ? "" : "",
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontSize: MediaQuery.of(context).size.width * 0.055,
),
),
onTap: () {
value.showModal();
},
title: Text(
_selectedLevel != null ? _selectedLevel! : "Choose",
style: TextStyle(
fontSize: MediaQuery.of(context).size.width * 0.055,
color: Theme.of(context).colorScheme.primary,
overflow: TextOverflow.ellipsis,
),
),
loadingText: "",
trailing: Icon(
FontAwesomeIcons.angleDown,
color: Theme.of(context).colorScheme.primary,
),
),
)
],
),
);
},
modalConfig: const S2ModalConfig(
title: '',
type: S2ModalType.bottomSheet,
),
choiceConfig: S2ChoiceConfig(
type: S2ChoiceType.radios,
style: S2ChoiceStyle(
showCheckmark: true,
color: Theme.of(context).colorScheme.primary,
titleStyle: TextStyle(
fontSize: MediaQuery.of(context).size.width * 0.055,
color: Theme.of(context).colorScheme.primary,
),
),
),
choiceBuilder: (context, item, isSelected) {
return Padding(
padding: EdgeInsets.symmetric(
vertical: MediaQuery.of(context).size.height * 0.015,
horizontal: MediaQuery.of(context).size.width * 0.03,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap: () {
setState(() {
_selectedLevel = isSelected.value;
});
if (_selectedLevel != null) {
setState(() {
item.onModalClose(true);
item.closeModal();
});
}
},
child: Row(
children: [
Icon(
_selectedLevel == isSelected.value ? FontAwesomeIcons.solidCircleCheck : FontAwesomeIcons.circle,
color: Theme.of(context).colorScheme.primary,
size: MediaQuery.of(context).size.width * 0.055,
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.05,
),
Text(
isSelected.value,
style: TextStyle(
overflow: TextOverflow.ellipsis,
fontSize: MediaQuery.of(context).size.width * 0.055,
color: Theme.of(context).colorScheme.primary,
),
),
],
),
),
Row(
children: [
GestureDetector(
onTap: () {
// TODO EDIT NAME SITE
},
child: Icon(
FontAwesomeIcons.penToSquare,
color: Theme.of(context).colorScheme.primary,
size: MediaQuery.of(context).size.width * 0.055,
),
),
SizedBox(
width: MediaQuery.of(context).size.width * 0.05,
),
GestureDetector(
onTap: () {
setState(() {
isSelected.value;
});
if (isSelected.value != null) {
CRUDMethodFirestore(
selectedLevel: isSelected.value,
itemModal: item,
context: context,
).delete();
}
setState(() {
_selectedLevel = null;
});
},
child: Icon(
FontAwesomeIcons.trash,
color: Theme.of(context).colorScheme.primary,
size: MediaQuery.of(context).size.width * 0.055,
),
),
],
)
],
),
);
},
),
The problem appears during the execution of my two GestureDetector, at the level of the onTap the dropdown menu (modal) closes having defined the new value in my initial value variable _selectedLevel, it works the value is well transmitted but the error message appears in the console but does not influence the objective of my code.
If you could help me solve my error that would be great, it tells me that S2SingleSelection was used after being disposed except in no case I dispose it for me.
Thanks.