连续流列出,没有重复
Posted
技术标签:
【中文标题】连续流列出,没有重复【英文标题】:Continuous stream to list with no repeats 【发布时间】:2021-02-05 00:33:50 【问题描述】:我有一个数据流,我想将其转换为键值对的列表/映射。我想将每个“故障”与相应的“严重性”配对并将这些对显示为列表。我的问题是我的列表不断增长,我无法检查正在添加的值是否已经在列表中。
代码:
List<int> severityList = [0];
List faultItems = [0];
var lastFault;
Widget _buildFaultOutput(snapshot)
//New growable lists with 0 set as the first value to prevent error
var msg = snapshot.data;
print(msg);
var faultList = msg["fault_list"];
print("faultList: $faultList");
var numberOfFaults = faultList.length;
print("Number of faults: $numberOfFaults");
if (faultList.length == 0)
return Text("None");
else
int i = 0;
for (var i = 0; i < faultList.length; i++)
// print(faults);
// print("i: $i");
var faults = faultList[i];
var motorCurrent = faults["fault"];
var severity = faults["severity"];
if (motorCurrent != lastFault)
faultItems.insert(i, motorCurrent);
severityList.insert(i, severity);
print('added $faultItems[i], severity: $severityList[i]');
lastFault = motorCurrent;
else
//TODO: add list of faults with key/value pairs (fault:severity): Text of "motorCurrent" in color of severity
//TODO: Print each individual item from list with severity
// return Text(
// "Number of Faults: $faultList.length\n$faultItems\nSeverity: $severityList[i]");
return Text(
"Number of Faults: $faultList.length\n$faultItems\nSeverity: $severityList");
示例数据:
I/flutter (21022): fault_list: [fault: voltage fault, process_name: BetaFirmware::bmsVoltageFaultCallback(), severity: 0, time_stamp: secs: 1603209904, nsecs: 581818990, fault: motor temp: 2, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 575800930, fault: motor temp: 5, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 575800930, fault: motor temp: 6, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 620800930, fault: motor temp: 3, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 620800930, fault: motor temp: 9, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 620800930, fault: motor temp: 4, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 620800930, fault: motor temp: 7, process_na
I/flutter (21022): faultList: [fault: voltage fault, process_name: BetaFirmware::bmsVoltageFaultCallback(), severity: 0, time_stamp: secs: 1603209904, nsecs: 581818990, fault: motor temp: 2, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 575800930, fault: motor temp: 5, process_name: BetaFirmwareBase::checkMotorSafety(), severity: 2, time_stamp: secs: 1603209905, nsecs: 575800930, fault: motor temp: 6,
【问题讨论】:
【参考方案1】:在方法_buildFaultOutput(snapshot)的开头添加severityList.clear()和faultList.clear()行
【讨论】:
谢谢!这正是我所需要的! 你知道如何并排显示故障列表和严重性列表中的每个项目吗? 在列表视图中返回 Row 小部件,并将故障列表项和严重性列表项放置为子项以上是关于连续流列出,没有重复的主要内容,如果未能解决你的问题,请参考以下文章