我使用这个数组在Text Widget中使用它的值:
var heartData = ['76','76','80', '76','82','75','73','75'];现在,我想在text Widget中逐个显示这些数组数据:
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中使用此文本,当满足某个条件时,会显示文本小工具,我希望逐个获取此数据,而不是以列表形式。我怎样才能做到这一点呢?提前谢谢你!
发布于 2021-06-08 01:02:29
数组中有一个名为join的方法,您可以调用它:
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
https://stackoverflow.com/questions/67873351
复制相似问题