Home > Mobile >  database update function not working sqflite flutter
database update function not working sqflite flutter

Time:12-27

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);

}

CodePudding user response:

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.

CodePudding user response:

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

  • Related