A SnackBar is a lightweight message widget that appears at the bottom of the screen to inform users of an action or event. It can include a message, action button, and auto-dismiss after a few seconds.
Source Code
//write this function one time and use snackbar just calling MySnackbar function
MySnackbar(message,context){
return ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
action: SnackBarAction(
label: 'UNDO',
onPressed: () {
// Reverse the action here
print('Undo pressed');
},
),
);
}
//use anywhere jus calling the function with text parameter
MySnackbar("This is for ac unit icon", context);
Ai Code Analizer
✅ Summary of Key Properties
| Property | Description |
|---|---|
content | Main message (usually a Text widget) |
action | Optional action like “UNDO”, “RETRY”, etc. |
duration | How long the SnackBar stays visible |
backgroundColor | Background color |
shape | Customize border shape (e.g., rounded) |
behavior | fixed or floating position |
