flattenList function

List flattenList(
  1. List list
)

Implementation

List<dynamic> flattenList(List<dynamic> list) {
  // Keep track of current nesting level, add each element to a new list if it's not a list
  List<dynamic> result = [];

  for (var element in list) {
    if (element is List) {
      // If the element is a list, recursively flatten it
      result.addAll(flattenList(element));
    } else {
      // If the element is not a list, add it to the result list
      result.add(element);
    }
  }

  return result;
}