Issue
I was wondering how to implement GetX’s Snackbar but with actions. I know how to write SnackbarActions on the usual ScaffoldSnackbar provided with Flutter. I was wondering if there was a way to get this same functionality in GetX’s Snackbar. As you may be able to guess, I am trying to implement an undo functionality, and I wrote the rest of my app with GetX Snackbars.
This is how I know how to show a Snackbar with Actions
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content:
Text("Deleted ${item.matchNumber.value}"),
action: SnackBarAction(
label: "Undo",
onPressed: () => controller.documentsHelper
.saveMatchData(item),
),
duration: const Duration(seconds: 3),
),
);
How would get this functionality through GetX? Thanks!
Solution
Try this
Get.snackbar(
'Snackber',
'Deleted ${item.matchNumber.value}',
duration: const Duration(seconds: 3),
colorText: Colors.black,
backgroundColor: Colors.white,
snackPosition: SnackPosition.BOTTOM,
maxWidth: Get.width,
mainButton: TextButton(
child: Text('Undo'),
onPressed: () {
controller.documentsHelper
.saveMatchData(item);
},
),
);
Answered By – Shahoriar Nahid
Answer Checked By – David Goodson (FlutterFixes Volunteer)