Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix a value of type future<int> can not be assigned to a variable of type int

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);
like image 865
Ben Ghaleb Avatar asked Dec 09 '25 17:12

Ben Ghaleb


1 Answers

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
});
like image 84
Vijay Patidar Avatar answered Dec 12 '25 06:12

Vijay Patidar