我有一个单行代码,该代码删除尾随空格和前导空格,并且还用单个空格替换了中间的多个空格。 (来自字符串)
value = value..trim()..split(" +")..join(" ");
但是我收到以下错误。The method 'join' isn't defined for the type 'String'.
Try correcting the name to the name of an existing method, or defining a method named 'join'.(dartundefined_method)
我做错了什么?
最佳答案
您不需要在那里的级联表示法:
value = value.split(' ').where((x) => x.isNotEmpty).map((x) => x.trim()).join(" ")
关于flutter - 为什么在Dart中执行“方法级联”时出现此错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62824915/