如何从我在文本字段中输入的单词输出代码

问题描述 投票:0回答:1

我所做的是根据需要导出编码。我的代码有一点难以解决的问题,所以希望你能帮忙。

这是我的代码:

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),
  ],
);

这是该项目的图片:

flutter encryption textfield
1个回答
0
投票

问题在于

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
的更多信息分割方法

© www.soinside.com 2019 - 2024. All rights reserved.