-1
I need to change only the comment field of a contact. But when I try to change this field accuses this error type 'int' is not a subtype of type 'Client'
. I wonder why, since the update function passes the contact id.
Model function for comment update:
updateComents(Client id) async {
final db = await database;
var res = await db.update("Contatos", id.toJson(),
where: "id = ?", whereArgs: [id.id]);
return res;
}
Function of the select in the bank:
Future<List> getRows() async{
final db = await database;
var res = await db.rawQuery("SELECT * FROM Contatos ORDER BY fullname");
return res.toList();
}
contactsList is assigned to getRows: contactsList = await getRows();
Button where I call this function:
child: CupertinoButton(
onPressed: (){
model.updateComents(model.contactsList[index]["id"]);
},
child: Text("Salvar Alterações")
),
I’m new to Dart/flutter with database.
What kind of list
model.contactsList
?– Matheus Ribeiro
Is a variable assigned to a query in the database that sorts by name.
– Marcelo Lemos 7
So what kind of list? For example, it is a list of this kind
List<Client>
? 'Cause if it’s you I could do it on the buttonmodel.updateComents(model.contactsList[index]
without putting the["id"]
– Matheus Ribeiro
Ah yes it is a
Future<List>
– Marcelo Lemos 7
Test the way I suggested in the comment above, if it works I create a more complete answer.
– Matheus Ribeiro
Not yet returns error
type 'QueryRow' is not a subtype of type 'Client'
– Marcelo Lemos 7
Not knowing the right type of list and what is received on it gets kind of hard... EDIT your question and put how you do to feed that list and what data it gets. And specify its type, for example
Future<List<TipoTal>>
– Matheus Ribeiro
Debug your project as well and tell us if the error occurs at the button click or inside the method
updateComents
– Matheus Ribeiro
I’m going to check what you asked for, I’m a little confused because it wasn’t me who created the code so until I understand I’m a little lost too.
– Marcelo Lemos 7
The problem is that you’re passing one
int
to a function that awaits aClient
. Probably the correct would be to call as suggested by @Matheusribeiro:model.contactsList[index]
.– Renan Gomes
Yes, I’ve just passed the
model.contactsList[index]
and returned the errortype 'QueryRow' is not a subtype of type 'Client'
– Marcelo Lemos 7
@Matheusribeiro made the edition, it was clearer this way ?
– Marcelo Lemos 7
Yes, as soon as possible I create an answer.
– Matheus Ribeiro
@Matheusribeiro Thanks
– Marcelo Lemos 7