Skip to content

Commit ab7b2ed

Browse files
committed
Adicionado snackBar para recuperar item apagado
1 parent b7a4d5d commit ab7b2ed

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

lib/main.dart

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ class Home extends StatefulWidget {
2121
class _HomeState extends State<Home> {
2222
List<Map> _todoList = [];
2323

24-
25-
Map<String,dynamic> _ultimoRemovido;
26-
int _ultimoRemovidoPosicao;
24+
Map<String, dynamic> _ultimoRemovido;
25+
int _ultimoRemovidoPosicao;
2726

2827
final _tarefaController = TextEditingController();
2928

@@ -138,14 +137,26 @@ class _HomeState extends State<Home> {
138137
});
139138
},
140139
),
141-
onDismissed: (direction){
140+
onDismissed: (direction) {
142141
setState(() {
143142
_ultimoRemovido = Map.from(_todoList[index]);
144-
_ultimoRemovidoPosicao = index;
145-
_todoList.removeAt(index);
146-
_saveTarefas();
143+
_ultimoRemovidoPosicao = index;
144+
_todoList.removeAt(index);
145+
_saveTarefas();
146+
final snack = SnackBar(
147+
content: Text("Tarefa \"${_ultimoRemovido["tittle"]}\" removida"),
148+
action: SnackBarAction(
149+
label: "Desfazer",
150+
onPressed: () {
151+
setState(() {
152+
_todoList.insert(_ultimoRemovidoPosicao, _ultimoRemovido);
153+
_saveTarefas();
154+
});
155+
}),
156+
duration: Duration(seconds: 3),
157+
);
158+
Scaffold.of(context).showSnackBar(snack);
147159
});
148-
149160
},
150161
);
151162
}

0 commit comments

Comments
 (0)