doc/api/overlay_entry/refreshSpecificOverlayEntries.html
voidrefreshSpecificOverlayEntries(
)
Refresh an specific entry instead of all of entries to enhance the performace
container : The container you want to operate, it is related with internal OverlayEntrymode : The BoostSpecificEntryRefreshMode you want to choose
void refreshSpecificOverlayEntries(
BoostContainer container, BoostSpecificEntryRefreshMode mode) {
//Get OverlayState from global key
final overlayState = overlayKey.currentState;
if (overlayState == null) {
return;
}
//deal with different situation
switch (mode) {
case BoostSpecificEntryRefreshMode.add:
final entry = _ContainerOverlayEntry(container);
_lastEntries.add(entry);
overlayState.insert(entry);
break;
case BoostSpecificEntryRefreshMode.remove:
if (_lastEntries.isNotEmpty) {
//Find the entry matching the container
final entryToRemove = _lastEntries.singleWhere((element) {
return element.containerUniqueId == container.pageInfo.uniqueId;
});
//remove from the list and overlay
_lastEntries.remove(entryToRemove);
entryToRemove.remove();
// https://github.com/alibaba/flutter_boost/issues/1056
// Ensure this frame is refreshed after schedule frame,
// otherwise the PageState.dispose may not be called
SchedulerBinding.instance.scheduleWarmUpFrame();
}
break;
case BoostSpecificEntryRefreshMode.moveToTop:
final existingEntry = _lastEntries.singleWhere((element) {
return element.containerUniqueId == container.pageInfo.uniqueId;
});
//remove the entry from list and overlay
//and insert it to list'top and overlay 's top
_lastEntries.remove(existingEntry);
_lastEntries.add(existingEntry);
existingEntry.remove();
overlayState.insert(existingEntry);
break;
}
}