【发布时间】:2019-04-08 10:14:56
【问题描述】:
我正在尝试构建一个包含不同游戏列表的应用。作为后端,我使用 Firebase 并且连接工作正常,我对其进行了测试。无论如何,我在用来自 firebase 的真实数据替换模拟数据时遇到问题。我总是收到这个错误:
type 'Future ' 不是 type 'List ' 的子类型
我有以下功能:
getGames() async{
List newGamesList = [];
QuerySnapshot result = awaitFirestore.instance.collection('products').getDocuments();
List<DocumentSnapshot> documents = result.documents;
documents.forEach((DocumentSnapshot doc) {
Game game = new Game.fromDocument(doc);
newGamesList.add(game);
});
}
“游戏”是这样的:
factory Game.fromDocument(DocumentSnapshot document) {
return new Game(
name: document['name'],
box: document['box'],
cover: document['cover'],
description: document['description'],
);
}
在我的构建小部件中,我称之为“getGames”:
new HorizontalGameController(getGames()),
知道为什么会发生此错误以及如何解决该错误吗?
编辑:
为了更好地理解这里是我的 HorizontalGameController:
class HorizontalGameController extends StatelessWidget {
HorizontalGameController(this.gameItems);
final List<Game> gameItems;
@override
Widget build(BuildContext context) {
return new SizedBox.fromSize(
size: const Size.fromHeight(240.0),
child: new ListView.builder(
itemCount: 1,
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.only(left: 12.0, top: 4.0),
itemBuilder: (BuildContext context, int position) {
return GameContainerItem(context, gameItems[position]);
}),
);
}
}
【问题讨论】:
标签: firebase flutter google-cloud-firestore