getNextAdUnit method

String? getNextAdUnit(
  1. String adType
)

✅ Get next available Ad Unit ID for a specific ad type (rotation logic)

Implementation

String? getNextAdUnit(String adType) {
  if (_adsList.isEmpty) return null;

  int startIndex = _currentAdIndex;
  do {
    final ad = _adsList[_currentAdIndex];
    _currentAdIndex = (_currentAdIndex + 1) % _adsList.length;

    if (ad.adsType == adType) {
      return ad.adUnitId;
    }
  } while (_currentAdIndex != startIndex);

  return null; // No matching ad type found
}