removeTextElement static method

List<TextElement> removeTextElement(
  1. List<TextElement> elementList,
  2. String text
)

Remove the TextElements from the list corresponding to the text Ex :

List<BrsTextElement> elementList =  ['How', 'are', 'you', '?'];
String text = 'are you';
Result : elementList = ['How','?']

Implementation

static List<TextElement> removeTextElement(
    List<TextElement> elementList, String text) {
  for (int i = 0; i < elementList.length; i++) {
    String concatenation = elementList[i].text;
    if (concatenation == text) {
      elementList.removeAt(i);
      i = 0;
      continue;
    } else {
      for (int j = i + 1; j < elementList.length; j++) {
        concatenation += ' ${elementList[j].text}';
        if (concatenation == text) {
          elementList.removeRange(i, j + 1);
          i = 0;
          break;
        }
        if (concatenation.length > text.length) {
          break;
        }
      }
    }
  }

  return elementList;
}