首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在文本小部件中一次显示一个数组项

在文本小部件中一次显示一个数组项
EN

Stack Overflow用户
提问于 2021-06-07 22:17:11
回答 1查看 23关注 0票数 0

我使用这个数组在Text Widget中使用它的值:

代码语言:javascript
复制
var heartData = ['76','76','80', '76','82','75','73','75'];

现在,我想在text Widget中逐个显示这些数组数据:

代码语言:javascript
复制
StreamBuilder<List<int>>(
                                    stream: stream,
                                    initialData: lastValue,
                                    builder: (BuildContext context,
                                        AsyncSnapshot<List<int>> snapshot) {
                                      if (snapshot.connectionState ==
                                          ConnectionState.active) {
                                        var currentVal =
                                            snapshot.data.toString();
                                        int currentValue = int.parse(
                                            currentVal.substring(
                                                1, currentVal.length - 1),
                                            onError: (source) => -1);
                                        print("String data $currentValue");
                                        if (currentValue == 2) {
                                      
                                          return FutureBuilder(
                                              future: Future.delayed(
                                                  const Duration(seconds: 0),
                                                  () async {
    
                                                Seziurealert();
                                              }),
                                              builder: (context, snapshot) {
             // I want to display array data here one by one
                                                return Text(
                                                  'heartData[i]',
                                                  style: TextStyle(
                                                    fontFamily:
                                                        'SF Pro Display',
                                                    fontSize: 19,
                                                    color:
                                                        const Color(0xffffffff),
                                                    fontWeight: FontWeight.w500,
                                                    height: 1.4736842105263157,
                                                  ),
                                                );
                                              });
                                        } else if (currentValue == 0) {
                                          return Text(
                                            'Device not calibrated',
                                            style: TextStyle(
                                              fontFamily: 'SF Pro Display',
                                              fontSize: 19,
                                              color: const Color(0xffffffff),
                                              fontWeight: FontWeight.w500,
                                              height: 1.4736842105263157,
                                            ),
                                          );
                                        } else if (currentValue == 1) {
    // I want to display array data here one by one
                                          return Text(
                                            'heartData[i]',
                                            style: TextStyle(
                                              fontFamily: 'SF Pro Display',
                                              fontSize: 19,
                                              color: const Color(0xffffffff),
                                              fontWeight: FontWeight.w500,
                                              height: 1.4736842105263157,
                                            ),
                                          );
                                        }
    // I want to display array data here one by one
                                        return Text(
                                          'heartData[i]',
                                          style: TextStyle(
                                            fontFamily: 'SF Pro Display',
                                            fontSize: 19,
                                            color: const Color(0xffffffff),
                                            fontWeight: FontWeight.w500,
                                            height: 1.4736842105263157,
                                          ),
                                        );
                                      } else {
                                        return Text(
                                          'Check the stream',
                                          style: TextStyle(
                                            fontFamily: 'SF Pro Display',
                                            fontSize: 19,
                                            color: const Color(0xffffffff),
                                            fontWeight: FontWeight.w500,
                                            height: 1.4736842105263157,
                                          ),
                                        );
                                      }
                                    },
                                  ),

请帮助我如何在我的文本小部件中使用这个数组?我在Stream Builder中使用此文本,当满足某个条件时,会显示文本小工具,我希望逐个获取此数据,而不是以列表形式。我怎样才能做到这一点呢?提前谢谢你!

EN

回答 1

Stack Overflow用户

发布于 2021-06-08 01:02:29

数组中有一个名为join的方法,您可以调用它:

代码语言:javascript
复制
 return Text(
  heartData.join(),
  style: TextStyle (
    fontFamily: 'SF Pro Display',
    fontSize: 19,
    color: const Color(0xffffffff),
    fontWeight: FontWeight.w500,
    height: 1.4736842105263157,
  ),
);

结果将是7676807682757375

您还可以将分隔符传递给此函数heartData.join(separator: "-")

结果将是76-76-80-76-82-75-73-75

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67873351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档