我所做的是根据需要导出编码。我的代码有一点难以解决的问题,所以希望你能帮忙。
这是我的代码:
String codecVal(String val) {
switch (val) {
case 'a':
return '19';
case 'b':
return '00';
case 'anh':
return '70'; // here is the problem, it only returns 19 not 70
default:
return "";
}
}
String someFunc(String val) {
String textLetter = val;
final textToList = textLetter.split('');
// textToList.sort(); //if you need to sorted number uncomment this line
final result = textToList.map((e) => codecVal(e)).toList();
return result.join("-");
}
return Column(
children: [
_buildTextEditingDeltaViewCode(someFunc(textCodeElec.toLowerCase())),
const SizedBox(height: 10),
],
);
这是该项目的图片:
问题在于
split method
总是将字符串拆分为单个字符
String textLetter="a anh b";
final textToList = textLetter.split('');
//this line will return ["a", "n", "h"," " , "a"," " ,"b"];
//always will split String to single char
// try the following
final textToList = textLetter.split(' ');
您可以在此链接中阅读有关
split method
的更多信息分割方法