I'm trying to insert a row to a table in database using flutter framework and when I'm assigning the returned value to a new variable I get the following error message
a value of type future<int> can not be assigned to a variable of type int
this is the function to insert new row
Future<int> addContact(String contact_name, String contact_phone) async {
Database c = await getConnection;
Map<String, dynamic> contact = getMap(contact_name, contact_phone);
return await c.insert("contacts", contact);
}
and here where I'm getting the returned data
int result=db.addContact(name, phone);
addContact function has some operation which will return value when operation complete, so make a completion block here.....
addContact(contact_name, contact_phone).then((value) {
//this 'value' is in int
//This is just like a completion block
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With