wrap static method

List<NavigatorObserver> wrap(
  1. List<NavigatorObserver>? navigatorObservers
)

Implementation

static List<NavigatorObserver> wrap(List<NavigatorObserver>? navigatorObservers) {
  if (navigatorObservers == null) {
    return [AutoTrackNavigationObserver()];
  }

  bool found = false;
  List<NavigatorObserver> removeList = [];
  for (NavigatorObserver observer in navigatorObservers) {
    if (observer is AutoTrackNavigationObserver) {
      if (found) {
        removeList.add(observer);
      }
      found = true;
    }
  }
  for (NavigatorObserver observer in removeList) {
    navigatorObservers.remove(observer);
  }
  if (!found) {
    navigatorObservers.insert(0, AutoTrackNavigationObserver());
  }
  return navigatorObservers;
}