I want to hide a material banner or snackbarafter 1 second and there should be a button to hide the current material banner or snackbar. I've did this way and worked. Waht do you think? Do you have more stylish and suggest best practice for this pattern?
MaterialBanner(
content: Text('Saved'),
actions: [
FutureBuilder(
future:
Future.delayed(Duration(seconds: 2)),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.done) {
//auto hide scaffold messenger
ScaffoldMessenger.of(context)
.hideCurrentMaterialBanner();
}
return TextButton(
onPressed: () {
ScaffoldMessenger.of(context)
.hideCurrentMaterialBanner();
},
child: Text('hide'),
);
}),
],
),