Skip to content

Commit 3fbb0cd

Browse files
Added a undo button. Therefore a note can pushed back into current tasks from completed tasks.
1 parent 1570b09 commit 3fbb0cd

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

lib/completedTasks.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ class _CompletedTasksState extends State<CompletedTasks> {
1515
List<Note> completedTasks = Storage.completedNotes;
1616
return ListView.builder(
1717
itemBuilder: (BuildContext context, int index) {
18-
return NoteCardCompleted(note: completedTasks[index], myFunc: () {
19-
setState(() {
20-
Storage.removeNoteCompleted(note: completedTasks[index]);
21-
});
22-
});
18+
return NoteCardCompleted(
19+
note: completedTasks[index],
20+
myFunc: () {
21+
setState(() {
22+
Storage.removeNoteCompleted(note: completedTasks[index]);
23+
});
24+
},
25+
undo: () {
26+
setState(() {
27+
Storage.undo(note: completedTasks[index]);
28+
});
29+
},
30+
);
2331
},
2432
itemCount: completedTasks.length,
2533
);

lib/note.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class NoteCard extends StatelessWidget {
8888
class NoteCardCompleted extends StatelessWidget {
8989
final Note note;
9090
final VoidCallback myFunc;
91-
NoteCardCompleted({required this.note, required this.myFunc});
91+
final VoidCallback undo;
92+
NoteCardCompleted({required this.note, required this.myFunc, required this.undo});
9293

9394
@override
9495
Widget build(BuildContext context) {
@@ -141,14 +142,14 @@ class NoteCardCompleted extends StatelessWidget {
141142
),
142143
],
143144
),
144-
IconButton(onPressed: myFunc, icon: Icon(Icons.delete_rounded)),
145-
// Row(
146-
// mainAxisAlignment: MainAxisAlignment.spaceAround,
147-
// children: <Widget>[
148-
// IconButton(onPressed: myFunc, icon: Icon(Icons.delete_rounded)),
149-
// IconButton(onPressed: myFunc, icon: Icon(Icons.check)),
150-
// ],
151-
// ),
145+
// IconButton(onPressed: myFunc, icon: Icon(Icons.delete_rounded)),
146+
Row(
147+
mainAxisAlignment: MainAxisAlignment.spaceAround,
148+
children: <Widget>[
149+
IconButton(onPressed: myFunc, icon: Icon(Icons.delete_rounded)),
150+
IconButton(onPressed: undo, icon: Icon(Icons.undo)),
151+
],
152+
),
152153
],
153154
),
154155
),

lib/storage.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,17 @@ class Storage {
6666
}
6767
}
6868
}
69+
70+
static void undo({required Note note}) {
71+
notes.add(note);
72+
localStorage.add(note);
73+
completedNotes.remove(note);
74+
75+
for(var k in completed.keys) {
76+
if(note == completed.get(k)) {
77+
completed.delete(k);
78+
break;
79+
}
80+
}
81+
}
6982
}

0 commit comments

Comments
 (0)