-1

am quite new to flutter and my code is pretty much a mess but can anyone explain why db. update doesn't work, whenever I try to update it throws this error

"error when trying to update"(https://i.stack.imgur.com/4cCdt.png)

"code"(https://i.stack.imgur.com/yDoIl.png)

"UI" (https://i.stack.imgur.com/HkahR.png)

all that its supposed to do is when the save icon is pressed it takes input from both title and body and saves them as it is shown above, but instead it throws the error when trying to update. can anyone help please ?

this how my update function goes:

Future update(Note note) async { final db = await instance.database;

final id = await db.update(
    tableNotes,
    note.toJson(),
    where: '${NoteFields.id} = ?',
    whereArgs: [note.id]);
return note.copy(id: id);

}

2 Answers2

0

As per your screenshot, the data you are passing is null, that's why it is showing an error, before updating check what data you are sending.

  • the txt and txt2 reference to a text editing controller which is not empty,i have checked this by prinnting out the txt and txt 2 text when hitting the save icon – Jaffar Debsawi Dec 26 '22 at 09:58
  • @JaffarDebsawi I this there is a problem with the future methods. Try this await db.updateNote (Note(title: txt2.text, body: txt.text)). .then(() { Navigator.of (context).push( MaterialPageRoute ( builder: (context) => MyHomePage(), ), // MaterialPageRoute ); }); – Krina Bhojani Dec 27 '22 at 07:21
0

solved it by adding the parameter id which then specifyed what it was adding txt and txt2 to