@override
Widget build(BuildContext context) {
final AppStateManager manager = AppStateManager.of(context);
String textLetter = manager.appState.replacementsController.text;
String textCodeElec = manager.appState.replacementsController.value.text;
log('data: ${manager.appState.textEditingDeltaHistory.length}');
if (textLetter == 'a' || textLetter == 'A') {
textCodeElec = '90'; //a print 90
}
if (textLetter == 'b' || textLetter == 'B') {
textCodeElec = '88';// b print 88
}
if (textLetter == 'ao' || textLetter == 'Ao') {
textCodeElec = '94';// but bao print bao are not 88 94
}
// log('textLetter: ${textLetter}');
log('textCodeElec: ${textCodeElec}');
return Column(
children: [
_buildTextEditingDeltaViewCode(textCodeElec),
_buildTextEditingDeltaViewHeader(),
Expanded(
child: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 35.0),
itemBuilder: (context, index) {
return _buildTextEditingDeltaHistoryViews(
manager.appState.textEditingDeltaHistory)[index];
},
itemCount: manager.appState.textEditingDeltaHistory.length,
separatorBuilder: (context, index) {
return const SizedBox(height: 2.0);
},
),
),
const SizedBox(height: 10),
],
);
}
I have tried many ways but it still does not display as requested when b = 88, ao = 94 but ‘bao = bao’ is not ‘bao = 88 94’.
What can I try next?
2
Answers
bao
is a different value thanb
andao
.If you want to display
88 94
when value isbao
then you should add:to your code.
Your goal
When the user types text, it should test if it starts with some key characters (a, b, ao), if this is the case it should add to textCodeElec a number, check if the rest of the value is equal to others key character and add them if it is the case.
Ecamples:
The reason why it doesn’t work
In your conditions, you are using "==" comparator so when you type "bao" it is not equal to "b" or "ao" which is why it returns the same value.
Solution
To solve that you can use startsWith which will check if the value start with a key character, if it is the case you will the value of that key and then retrieve that key for the text so you can test it with next key values.