如何首先应用从Firebase收到的数据?

发布于 2025-01-24 04:36:35 字数 1638 浏览 0 评论 0原文

给定以下代码:

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文