'Dart manual translation text problem with double letter key's value never shows

I'm currently facing this problem with flutter (dart):

var data = {
 "U": "উ",
 "UU": "ঊ",
}

UU's value never get printed it print U's value twice and this is the code I'm using on TextField onchange(val) method:

onChanged: (val){
   editingController.selection = TextSelection.fromPosition(TextPosition(offset: editingController.text.length));
   setState(() {
     offset = editingController.selection.extentOffset;
     text = editingController.text;
     translated = [];
     myArr = val.split('');

   if(value == " " || value.contains('\n') || value.contains('\b')){
     text = "";
   }else{
     myArr.forEach((element) {
       if(data.containsKey(element)) {

           translated.add(data[element]);

        }
     });

     print(translated.toList().join(''));

   }
    
  })
}

Input: UU
Output:
[উ, উ] not [ঊ]


Solution 1:[1]

I came up with an answer with reduce. The idea is that I can actually get repeated value by the following method and append it to the same index of the array (where repeating started) with following code:

["U","U"].reduce((element, prev) {
       if(element == prev) {

           print(element+prev);

        }
        return element+prev;
     });
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Asif