如何首先应用从Firebase收到的数据?
给定以下代码:
Widget Topstocklist(Size size) {
firestore
.collection('stock')
.orderBy("dailynewscount", descending: true)
.limit(1)
.get()
.then((QuerySnapshot qs)
{
qs.docs.forEach((doc){
name = (doc['name']);
perc = (doc['perc']);
price = (doc['price']);
newscount = (doc['dailynewscount']);
print("100");
});
}
);
return Container(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
'',
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.7),
fontFamily: 'Content',
fontSize: size.width * 0.025,
fontWeight: FontWeight.normal,
height: 1,
),
) // Firebase 적용 사항
,
Container(
child: Column(
children: [
Topstock(size, "deci", "+3.2%", 75000, 1200),
Topstock(size, name, perc, price ,newscount),
],
))
]));
}
Widget Topstock(Size size, String stockname, var stockperc, var stockprice, var newscount) {
print(stockperc);
}
关键点代码: 打印(“ 100”)
打印(stockperc)
。
预期
I/flutter (15287): 100
I/flutter (15287): //perc = (doc['perc']);
I/flutter (15287): +3.2%
输出
I/flutter (15287): +3.2%
I/flutter (15287):
I/flutter (15287): 100
我认为,在从firebase导入数据之前,我认为这个问题与任务处理有关,即,异步工作,但是我还没有找到解决
方案来自Firebase的数据,然后运行TopStock代码?
Given the following code :
Widget Topstocklist(Size size) {
firestore
.collection('stock')
.orderBy("dailynewscount", descending: true)
.limit(1)
.get()
.then((QuerySnapshot qs)
{
qs.docs.forEach((doc){
name = (doc['name']);
perc = (doc['perc']);
price = (doc['price']);
newscount = (doc['dailynewscount']);
print("100");
});
}
);
return Container(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
'',
style: TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.7),
fontFamily: 'Content',
fontSize: size.width * 0.025,
fontWeight: FontWeight.normal,
height: 1,
),
) // Firebase 적용 사항
,
Container(
child: Column(
children: [
Topstock(size, "deci", "+3.2%", 75000, 1200),
Topstock(size, name, perc, price ,newscount),
],
))
]));
}
Widget Topstock(Size size, String stockname, var stockperc, var stockprice, var newscount) {
print(stockperc);
}
Key point code :print("100")
print(stockperc)
.
Expected
I/flutter (15287): 100
I/flutter (15287): //perc = (doc['perc']);
I/flutter (15287): +3.2%
output
I/flutter (15287): +3.2%
I/flutter (15287):
I/flutter (15287): 100
I think this problem relates to the task processing, i.e., asynchronous work, before importing data from the Firebase, but I have not found a solution
How can I get the data from the Firebase and then run the Topstock code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论