Skip to content

Commit 532ba44

Browse files
committed
UI pin
1 parent 3616cde commit 532ba44

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

note_app/lib/model/NotesList.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ class NotesList extends ChangeNotifier {
9898
}
9999
}
100100

101+
void togglePin(Note toggledNote) {
102+
if (toggledNote.pinned) {
103+
pinNote(toggledNote);
104+
} else {
105+
unpinNote(toggledNote);
106+
}
107+
}
108+
101109
Note getNoteWithID(int id) {
102110
for (var note in notes) {
103111
if (note.id == id) {

note_app/lib/model/Plaintext.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import 'Note.dart';
33
class Plaintext extends Note {
44
String content;
55

6-
Plaintext(id, {title = '', this.content = ''}) : super(id, title: title);
6+
Plaintext(id, {title = '', this.content = '', pinned = false})
7+
: super(id, title: title, pinned: pinned);
78

89
Plaintext.fromJSON(Map<String, dynamic> json)
910
: content = json['content'],
10-
super(json['id'] as int, title: json['title']);
11+
super(json['id'] as int, title: json['title'], pinned: json['pinned']);
1112

1213
Map<String, dynamic> toJson() => {
1314
'id': id,

note_app/lib/model/checklist/Checklist.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import '../Note.dart';
55
class Checklist extends Note {
66
List<ChecklistElement> chContent;
77

8-
Checklist(id, {title = '', chContent = const []})
8+
Checklist(id, {title = '', chContent = const [], pinned = false})
99
: chContent = contentConstructor(chContent),
10-
super(id, title: title);
10+
super(id, title: title, pinned: pinned);
1111

1212
Checklist.fromJSON(Map<String, dynamic> json)
1313
: chContent = getContent(json['content']),
14-
super(json['id'] as int, title: json['title']);
14+
super(json['id'] as int, title: json['title'], pinned: json['pinned']);
1515

1616
Map<String, dynamic> toJson() {
1717
Map<String, dynamic> json = {};

note_app/lib/widget/NoteTile.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:flutter/material.dart';
2+
import 'package:note_app/model/Note.dart';
23
import 'package:note_app/model/NotesList.dart';
34
import 'package:note_app/model/Plaintext.dart';
5+
import 'package:note_app/model/checklist/Checklist.dart';
46
import 'package:note_app/model/checklist/ChecklistManager.dart';
57
import 'package:note_app/screen/ChecklistPage.dart';
68
import 'package:note_app/screen/PlaintextPage.dart';
@@ -41,7 +43,9 @@ class _NoteTileState extends State<NoteTile> {
4143
String title = note.title == '' ? 'New note' : note.title;
4244
return ListTile(
4345
onTap: _onTap,
46+
onLongPress: _onLongPress,
4447
leading: icon,
48+
trailing: note.pinned ? Icon(Icons.push_pin_rounded) : null,
4549
title: Text(title),
4650
minVerticalPadding: 20,
4751
horizontalTitleGap: 10,
@@ -60,4 +64,17 @@ class _NoteTileState extends State<NoteTile> {
6064
}
6165
Navigator.push(context, MaterialPageRoute(builder: (context) => notePage));
6266
}
67+
68+
void _onLongPress() {
69+
Note note = NotesList().getNoteWithID(widget.noteID);
70+
if (note is Plaintext) {
71+
Plaintext toggled = Plaintext(widget.noteID,
72+
title: note.title, content: note.content, pinned: !note.pinned);
73+
NotesList().togglePin(toggled);
74+
} else if (note is Checklist) {
75+
Checklist toggled = Checklist(widget.noteID,
76+
title: note.title, chContent: note.chContent, pinned: !note.pinned);
77+
NotesList().togglePin(toggled);
78+
}
79+
}
6380
}

0 commit comments

Comments
 (0)