【发布时间】:2021-06-07 14:17:10
【问题描述】:
我正在使用这个数组在 Text Widget 中使用它的值:
var heartData = ['76','76','80', '76','82','75','73','75'];
现在我想在文本小部件中一一显示这个数组数据:
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 中使用此文本,并且在满足条件时显示文本小部件 我想一一获取这些数据,而不是列表形式。我怎样才能做到这一点? 提前谢谢!
【问题讨论】: