if (textLetter.toLowerCase().contains('1')) {
textCodeElec += ' 19';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('2')) {
textCodeElec += ' 00';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('3')) {
textCodeElec += ' 70';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('4')) {
textCodeElec += ' 08';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('5')) {
textCodeElec += ' 56';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('6')) {
textCodeElec += ' 68';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('7')) {
textCodeElec += ' 20';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('8')) {
textCodeElec += ' 16';
textLetter = textLetter.substring(1);
}
if (textLetter.toLowerCase().contains('9')) {
textCodeElec += ' 27';
textLetter = textLetter.substring(1);
}
我还是不知道如何解决这个问题 当输入1到9时,textCodeElec会有条件地显示,但向后输入9到1只会显示数字。
尝试一下,我希望它能解决您的问题。
String someFunc(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("");
}
String codecVal(val) {
switch (val) {
case '1':
return ' 19';
case '2':
return ' 00';
case '3':
return ' 70';
case '4':
return ' 08';
case '5':
return ' 56';
case '6':
return ' 68';
case '7':
return ' 20';
case '8':
return ' 16';
case '9':
return ' 27';
default:
return "";
}
}
输入=987654321
输出= 27 16 20 68 56 08 70 00 19
输入=123456789
输出=19 00 70 08 56 68 20 16 27