Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoniomldev/3fea1fdfeb7736dc56d4e4eb96ac9647 to your computer and use it in GitHub Desktop.
Save antoniomldev/3fea1fdfeb7736dc56d4e4eb96ac9647 to your computer and use it in GitHub Desktop.
Swipe to Dismiss
void showSnackBar() {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('Você arquivou essa mensagem!')));
}
Future<bool> showAlertDialog() async {
return await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Deletar item'),
content: Text('Você tem certeza que deseja deletar?'),
actions: [
ElevatedButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text('Deletar')),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop(false);
},
child: Text('Cancelar'))
],
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SwipeToDismiss - Mensagens'),
centerTitle: true,
),
body: ListView.builder(
itemCount: minhasMensagens.length,
itemBuilder: (BuildContext context, int index) {
return Dismissible(
key: UniqueKey(),
child: ListTile(
title: Text(minhasMensagens[index].titulo),
subtitle: Text(minhasMensagens[index].corpo),
),
background: Container(
padding: EdgeInsets.all(20),
color: Colors.green[400],
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(Icons.archive_rounded),
],
),
),
secondaryBackground: Container(
padding: EdgeInsets.all(20),
color: Colors.red[400],
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(Icons.delete_sweep_rounded),
],
)),
onDismissed: (DismissDirection direction) {
if (direction == DismissDirection.startToEnd) {
return showSnackBar();
}
},
confirmDismiss: (DismissDirection direction) async {
if (direction == DismissDirection.endToStart) {
return await showAlertDialog();
}
return false;
});
},
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment