簡體   English   中英

如何從 FutureBuilder Flutter 增加價值

[英]How to increment value from FutureBuilder Flutter

如何增值? 在 Flutter 中,我需要在不添加 firestore data 1, 2, 3 ,非常感謝任何幫助。 這是我的代碼,請查看下面的圖片以供參考。 謝謝

  return FutureBuilder<DocumentSnapshot>(
  future: users.doc(widget.documentId).get(),
  builder: (context, snapshot) {
    if(snapshot.connectionState == ConnectionState.done){

      Map<String, dynamic> data = {};
      data = snapshot.data?.data() as Map<String, dynamic>;
      
      increment++;

      return Column(
        children: [
          Row(
            children: [
              Container(
                color: Colors.red[200],
                width: 50,
                child: Text(
                    increment.toString(), //<- increment this value 
                    style: TextStyle(
                      fontSize: SizeConfig.safeBlockHorizontal * 2.7,
                    )
                ),
              ),
              Container(
                color: Colors.green[200],
                width: 270,
                child: Text(
                  data['fullName'],
                  style: TextStyle(
                    fontSize: SizeConfig.safeBlockHorizontal * 3.06,
                  ),
                ),
              ),
            ],
          ),
        Divider(thickness: SizeConfig.safeBlockHorizontal * .27),
        ],
      );
    }
    Text("Loading.."),
  },
);

在此處輸入圖像描述

試試這個你會索引。

body: FutureBuilder<List<String>?>(
  future: getData(),
  builder: (context, snapshot) {
    if (snapshot.hasData &&
        snapshot.connectionState == ConnectionState.done) {
      return ListView.builder(
        itemCount: snapshot.data!.length,
        itemBuilder: (context, index) {
          return Text(snapshot.data?[index] ?? "got null");
        },
      );
    }

    /// handles others as you did on question
    else {
      return CircularProgressIndicator();
    }
  },

管理員或版主的權限,請刪除這個問題,感謝@Mahesh 的回答,但我寧願使用 StreamBuilder 來完成這項工作,現在它工作正常。 謝謝你。 請關閉或刪除此線程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM