I have a ListView of items in my app and each item of that list is wrapped in a Dismissible widget so as to enable swipe to delete functionality. I also have a FloatingActionButton and on pressing that I navigate to a new page. All the functionality involving swipe to dismiss works fine but if I press the floating action button after dismissing an item, an exception is thrown with the following message:
I/flutter (23062): A dismissed Dismissible widget is still part of the tree.
I/flutter (23062): Make sure to implement the onDismissed handler and to immediately remove the Dismissible
I/flutter (23062): widget from the application once that handler has fired.
Here's the code:
Widget build(BuildContext context) {
final String testVal = widget.testStr;
return Scaffold(
appBar: AppBar(
title: Text('My Device Info'),
),
body: FutureBuilder<AndroidDeviceInfo>(
future: _deviceInfoPlugin.androidInfo,
builder: (BuildContext context, AsyncSnapshot<AndroidDeviceInfo> snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
} else {
final androidDeviceInfo = snapshot.data;
return ListView(
children: <Widget>[
Dismissible(
key: Key('1'),
background: Container(color: Colors.red,),
onDismissed: (direction){
},
child: ListTile(
leading: Icon(Icons.info),
title: Text('Android build version: ${androidDeviceInfo.version.release}',
style: TextStyle(fontSize: 18.0),),
),
),
ListTile(
leading: Icon(Icons.info),
title: Text('Android device: ${androidDeviceInfo.device}',
style: TextStyle(fontSize: 18.0),),
),
ListTile(
leading: Icon(Icons.info),
title: Text('Android device hardware: ${androidDeviceInfo.hardware}', style: TextStyle(fontSize: 18.0),),
)
],
);
}
},
),
floatingActionButton: FloatingActionButton(
onPressed: (){
Navigator.of(context).push(MaterialPageRoute(builder: (context){ return new AboutPage();}));
},
child: Icon(Icons.add),
),
);
}
How can I avoid this exception from being thrown? Am I doing something wrong here?