我正在尝试从flutter
中的函数返回Future对象,我必须在数据库查询块中添加return语句,无法从外部访问它,但是出现此错误{{ 1}},因为期望在函数的末尾找到一个return语句,如果完整的示例在这里,则为:
Function has a return type of 'Future<Station>' but doesn't end with a return statement flutter
每当我尝试在函数末尾添加 Future<Station> gettingStationData(String stationName) async {
var databasesPath = await getDatabasesPath();
String path = join(databasesPath, 'main.db');
Database database = await openDatabase(path, version: 1);
database.transaction((tnx) async {
List<Map> stationQuery = await tnx.rawQuery(
"SELECT * FROM Station WHERE stationName = ?", [stationName]);
Station station = Station(
key: stationQuery[0]['key'],
stationName: stationQuery[0]['stationName'],
cityName: stationQuery[0]['cityName'],
stationLatitude: stationQuery[0]['stationLatitude'],
stationLongitude: stationQuery[0]['stationLongitude']);
return station;
});
}
时,都会给我return station;
错误。每当我尝试访问该函数时,它都会返回unresolved reference
。有什么帮助吗?
答案 0 :(得分:2)
您需要返回database.transaction(...)
返回的内容。
return database.transcation((tnx) async { ...