SnackBar Flutter

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

PropertyDescription
contentMain message (usually a Text widget)
actionOptional action like “UNDO”, “RETRY”, etc.
durationHow long the SnackBar stays visible
backgroundColorBackground color
shapeCustomize border shape (e.g., rounded)
behaviorfixed or floating position