Code for the snack bar when the elevated button is clicked.
ElevatedButton(
onPressed: () {
// define snackBar
SnackBar snackBar = SnackBar(
content: const Text(
"This is a snack bar",
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.green,
action: SnackBarAction(
label: "UNDO",
onPressed: () {
print("YOu clicked the UNDO action button!");
}),
);
//display the snack bar
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
// shape: BeveledRectangleBorder(
// borderRadius: BorderRadius.circular(
// 5.0,
// ),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
child: const Text(
"Elevated Button",
),
),
No comments:
Post a Comment