File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,4 +46,9 @@ class AppDatabase extends _$AppDatabase {
4646 Future <int > deleteNote (NoteData noteData) async {
4747 return await delete (note).delete (noteData);
4848 }
49+
50+ // UPDATE NOTES
51+ Future <bool > updateNote (NoteData noteData) async {
52+ return await update (note).replace (noteData);
53+ }
4954}
Original file line number Diff line number Diff line change @@ -105,16 +105,29 @@ class _NoteDetailPageState extends State<NoteDetailPage> {
105105 }
106106
107107 void _saveToDb () {
108- appDatabase
109- .insertNote (NoteCompanion (
110- title: dr.Value (titleEditingController.text),
111- description: dr.Value (descriptionEditingController.text),
112- color: dr.Value (1 ),
113- priority: dr.Value (1 ),
114- ))
115- .then ((value) {
116- Navigator .pop (context, true );
117- });
108+ if (widget.noteCompanion.id.present) {
109+ appDatabase
110+ .updateNote (NoteData (
111+ id: widget.noteCompanion.id.value,
112+ title: titleEditingController.text,
113+ description: descriptionEditingController.text,
114+ color: 1 ,
115+ priority: 1 ))
116+ .then ((value) {
117+ Navigator .pop (context, true );
118+ });
119+ } else {
120+ appDatabase
121+ .insertNote (NoteCompanion (
122+ title: dr.Value (titleEditingController.text),
123+ description: dr.Value (descriptionEditingController.text),
124+ color: dr.Value (1 ),
125+ priority: dr.Value (1 ),
126+ ))
127+ .then ((value) {
128+ Navigator .pop (context, true );
129+ });
130+ }
118131 }
119132
120133 void _deleteNotes () {
Original file line number Diff line number Diff line change @@ -108,11 +108,22 @@ class _NoteListPageState extends State<NoteListPage> {
108108 Row (
109109 mainAxisAlignment: MainAxisAlignment .spaceBetween,
110110 children: [
111- Text (noteData.title),
112- Text (_getPriority (noteData.priority! ))
111+ Expanded (
112+ child: Text (
113+ noteData.title,
114+ style: Theme .of (context).textTheme.bodyText2,
115+ ),
116+ ),
117+ Text (
118+ _getPriority (noteData.priority! ),
119+ style: TextStyle (color: _getColor (noteData.priority! )),
120+ )
113121 ],
114122 ),
115- Text (noteData.description),
123+ Text (
124+ noteData.description,
125+ style: Theme .of (context).textTheme.bodyText2,
126+ ),
116127 Row (
117128 mainAxisAlignment: MainAxisAlignment .end,
118129 children: [
@@ -156,4 +167,15 @@ class _NoteListPageState extends State<NoteListPage> {
156167 return '!' ;
157168 }
158169 }
170+
171+ _getColor (int priority) {
172+ switch (priority) {
173+ case 1 :
174+ return Colors .red;
175+ case 2 :
176+ return Colors .orange;
177+ default :
178+ return Colors .yellow;
179+ }
180+ }
159181}
You can’t perform that action at this time.
0 commit comments