expand method

Future<bool> expand(
  1. int index
)

Expands the item at the given index, returning true if expanded.

This method should typically not be called while the widget tree is being rebuilt.

Implementation

Future<bool> expand(int index) async {
  final controller = controllers[index];
  if (_expanded.contains(index) || controller == null) {
    return false;
  }

  final futures = <Future<void>>[];
  if (_max != null && _max <= _expanded.length) {
    final collapsing = _expanded.firstOrNull;
    if (collapsing == null) {
      return false;
    }

    _expanded.remove(collapsing);
    futures.add(controllers[collapsing]!.reverse());
  }

  _expanded.add(index);
  futures.add(controller.forward());

  await Future.wait(futures);
  notifyListeners();

  return true;
}