I have a list of Dismissible
widgets as follows:
Dismissible(
direction: DismissDirection.endToStart,
key: Key(widget.data[i]),
onDismissed: (direction) {
widget.onRemoveRequest(i, widget.data[i]);
},
background: Container(
color: Colors.red,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: Text(
"Delete",
textAlign: TextAlign.right,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
fontSize: 16.0,
),
),
),
],
),
),
child: CustomTextField(
padding: const EdgeInsets.only(left: 30.0, right: 30.0),
hintText: widget.newEntryHint,
text: widget.data[i],
keyboardType: TextInputType.multiline,
onChanged: (val) {
widget.onChanged(i, val);
},
),
)
It works as expected, except for when removing matching objects.
Note: widget.onRemoveRequest
removes the object at specified index from the source data, widget.data
.
widget.data
is a List<String>
. I provide these as the key
, however whenever I have two matching strings and dismiss one, I get an error because the Dismissible
isn't removed from the tree (understandable).
A dismissed Dismissible widget is still part of the tree.
So with a list of strings, how can I ensure each has a unique key, even if the actual strings are equal/match?