Back to Flutter Boost

refreshAllOverlayEntries function

doc/api/overlay_entry/refreshAllOverlayEntries.html

5.0.21.1 KB
Original Source

refreshAllOverlayEntries function

voidrefreshAllOverlayEntries(

  1. List<BoostContainer> containers

)

Refresh all of overlayEntries

Implementation

void refreshAllOverlayEntries(List<BoostContainer> containers) {
  final overlayState = overlayKey.currentState;
  if (overlayState == null) {
    return;
  }

  if (_lastEntries != null && _lastEntries.isNotEmpty) {
    for (var entry in _lastEntries) {
      entry.remove();
    }
  }

  _lastEntries = containers
      .map<_ContainerOverlayEntry>(
          (container) => _ContainerOverlayEntry(container))
      .toList(growable: true);

  overlayState.insertAll(_lastEntries);

  // https://github.com/alibaba/flutter_boost/issues/1056
  // Ensure this frame is refreshed after schedule frame,
  // otherwise the PageState.dispose may not be called
  final hasScheduledFrame = SchedulerBinding.instance.hasScheduledFrame;
  final framesEnabled = SchedulerBinding.instance.framesEnabled;
  if (hasScheduledFrame || !framesEnabled) {
    SchedulerBinding.instance.scheduleWarmUpFrame();
  }
}