updateActiveIndex method

Future<void> updateActiveIndex(
  1. int currentIndex
)

Updates active controllers based on the current scroll index. Instantiates at most 3 controllers, recycling idle controllers using URL swapping rather than disposing and recreating them.

Implementation

Future<void> updateActiveIndex(int currentIndex) async {
  _nextIndexToUpdate = currentIndex;

  // Update network connection status
  try {
    final netType = await VideoViewPlayerPlatform.instance.getNetworkType();
    if (_networkType != netType) {
      _networkType = netType;
      notifyListeners();
    }
  } catch (_) {}

  if (_isUpdating) return;
  _isUpdating = true;

  try {
    while (_nextIndexToUpdate != null) {
      final targetIndex = _nextIndexToUpdate!;
      _nextIndexToUpdate = null;
      await _performUpdate(targetIndex);
    }
  } finally {
    _isUpdating = false;
  }
}