如何在 flutter 中将复数数组转换为实数?

How to convert an array of complex numbers into real within flutter?

我想知道是否有办法将复数列表转换为实数列表。

[3.084580633850594 + 0.0i, 0.03930937672422563 + 0.0i, 25958.26505623091 + 0.0i, 28566.521479745476 + 0.0i]

我的方法是使用。

for (var item in list){
  double real = item.real;
}

https://pub.dartlang.org/documentation/my_complex/latest/my_complex/Complex/real.html

如果您有一个现有的复数列表,使用一些适当的 Complex 数字 class,使用 List.map 会更整洁:

var realParts = complexNumbers.map((z) => z.real);

请注意,这会给你一个 Iterable;如果你想要 List,你需要调用 Iterable.toList:

var realParts = complexNumbers.map((z) => z.real).toList();