Dismissible StreamBuilder getting error A dismissed Dismissible widget is still part of the tree.

1,459 views
Skip to first unread message

Samiran Majumder

unread,
Apr 22, 2019, 5:21:32 AM4/22/19
to Flutter Dev
Hi All,

I am facing issue with Dismissible widget  currently for my app i am using Dismissible widget with StreamBuilder and i am fetching record from firebase but i am getting error onDismissed .

Please find the error detail

A dismissed Dismissible widget is still part of the tree.

please find my code sniped for the same, if anyone know how to use it then please share some sample code.

Expanded(
child: StreamBuilder(
stream: Firestore.instance
.document('/users/User1/Trips/${widget.tripId}')
.collection('TropDocs')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text("Loading....");
return ListView.builder(
itemExtent: 150.0,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {

final item = snapshot.data.documents[index];
final itemID =
snapshot.data.documents[index].documentID;
final list = snapshot.data.documents;
return Dismissible(
key: Key(itemID),
// We also need to provide a function that tells our app
// what to do after an item has been swiped away.
onDismissed: (direction) {
// Remove the item from our data source.

//fBtDoc.deleteTraveldoc(item);
//Firestore.instance.collection('/users/User1/Trips/${widget.tripId}/TropDocs/').document('$itemID').delete();
setState(() {
list.removeAt(index);
});

// Then show a snackbar!
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text("$item dismissed")));
},
// Show a red background as the item is swiped away
background: Container(color: Colors.red),
child: _buildlistitem(
context, snapshot.data.documents[index])
);
}
);
},
),
)
]),
),

Maykon Ferreira

unread,
Jul 4, 2019, 2:59:01 PM7/4/19
to Flutter Development (flutter-dev)
It's been a long time since the question,but I think it will serve for those who have the same doubt in the future.
The item StreamBuilder he has snapshot.data, is correct then remove the item from it

onDismissed: (direction) {
    setState(() {
        snapshot.data.removeAt(index);
    });
}

Ken Corey

unread,
Jul 9, 2020, 7:34:42 AM7/9/20
to Flutter Development (flutter-dev)
I had a similar problem.  I solved it by setting the key for the Dismissable like this:

key: UniqueKey(),

Hope it helps.

-Ken
Reply all
Reply to author
Forward
0 new messages