【发布时间】:2019-05-10 00:13:23
【问题描述】:
我正在尝试将未来的返回值作为字符串接收。我该怎么办。
//Get a stock info
Future<String> getStock(int productID) async{
var dbClient = await db;
var result = await dbClient.rawQuery('SELECT * FROM $tableStock WHERE $columnProductID = $productID');
if(result.length == 0) return null;
return Stock.fromMap(result.first).currentStock;
}
Widget _buildProductInfo(Product data){
return Container(
child: ListView(
padding: EdgeInsets.all(8.0),
children: <Widget>[
_infoRow('Product ID', data.name),
_infoRow('Product Name', data.productID),
_infoRow('Cost Price', data.costPrice),
_infoRow('Selling Price', data.salePrice),
_infoRow('CategoryID', data.categoryID),
_infoRow('Currrent Stock', db.getStock(int.parse(data.productID)))
],
),
);
}
我希望这段代码显示一个“值”而不是“未来的实例”。但是我可以在尝试时打印返回值
final res = await db.getStock(int.parse(data.productID);
print(res);
【问题讨论】: