我将非常感谢任何能够提供帮助的人。我想在表中创建一列,该列来自我尝试此代码的每一行中的 col 1 + col 2 + col 3 的汇总,但结果不是汇总,而是喜欢从 col 1 和 col 2 连接...
rows: List<DataRow>.generate(
snapshot.data!.length,
(index) {
var data = snapshot.data![index];
return DataRow(
color: MaterialStateColor.resolveWith((states) =>
index % 2 == 1
? const Color.fromRGBO(34, 150, 243, 0.2)
: const Color.fromARGB(0, 140, 233, 148)),
cells: [
DataCell(
Text(
(Format.convertTo(
double.tryParse(data.lapus1_n1), 0)),
style: const TextStyle(
color: Color.fromARGB(255, 17, 17, 17),
fontWeight: FontWeight.normal,
fontSize: 12,
),
),
),
DataCell(
Text(
(Format.convertTo(
double.tryParse(data.lapus2_n1), 0)),
style: const TextStyle(
color: Color.fromARGB(255, 17, 17, 17),
fontWeight: FontWeight.normal,
fontSize: 12,
),
),
//textAlign: TextAlign.right,
),
DataCell(
Text(
(Format.convertTo(
double.tryParse(data.lapus3_n1), 0)),
style: const TextStyle(
color: Color.fromARGB(255, 17, 17, 17),
fontWeight: FontWeight.normal,
fontSize: 12,
),
),
),
DataCell(
Text(
(Format.convertTo(
double.tryParse(
data.lapus2_n1 + data.lapus3_n1),
0)),
style: const TextStyle(
color: Color.fromARGB(255, 17, 17, 17),
fontWeight: FontWeight.normal,
fontSize: 12,
),
),
),
]);
},
).toList(),
输出是这样的: 在此输入图片描述
像这样更改下面的代码并让我知道,
(Format.convertTo(double.tryParse(data.lapus2_n1),0) + double.tryParse(data.lapus3_n1),0)),
问题是您尝试添加字符串然后尝试解析它。只需解析两个值然后添加即可。