addToList static method

bool addToList({
  1. required List list,
  2. required int index,
  3. required dynamic element,
  4. required bool overwrite,
})

Adds an element to the list Adding must be in the correct order, so if the list is too small, then it won't be added Returns true, if the element was added

Implementation

static bool addToList({
  required List list,
  required int index,
  required dynamic element,
  required bool overwrite,
}) {
  if (index <= list.length) {
    if (index == list.length) {
      list.add(element);
    } else if (overwrite) {
      list[index] = element;
    }
    return true;
  } else {
    return false;
  }
}