我正在尝试使用 flutter 框架在数据库中的表中插入一行,当我将返回的值分配给新变量时,我收到以下错误消息
a value of type future<int> can not be assigned to a variable of type int
这是插入新行的函数
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);
}
这里是我获取返回数据的地方
int result=db.addContact(name, phone);
最佳答案
addContact函数有一些操作,操作完成后会返回值,所以在这里做一个完成 block .....
addContact(contact_name, contact_phone).then((value) {
//this 'value' is in int
//This is just like a completion block
});
关于dart - 如何修复 future<int> 类型的值不能分配给 int 类型的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52756388/