iampawan / VelocityX

A minimalist Flutter framework for rapidly building Flutter apps.

Home Page:https://velocityx.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Navigator - removeUri

carmas123 opened this issue · comments

Hi, the removeUri method of VxNavigator must find the latest index into the stack and not the first:

No we have this method into the code:

  /// remove a specific [Uri] and the corresponding [Page]
  void removeUri(Uri uri) {
    final index = _uris.indexOf(uri);
    if (index != -1) {
      final page = _pages.removeAt(index);
      final uri = _uris.removeAt(index);
      if (kIsWeb) {
        VxNav.replaceUrl(uri);
      }
      if (observers != null) {
        for (final observer in observers!) {
          observer.didChangeRoute(uri, page, "pop");
        }
      }
      notifyListeners();
    }
  }

it could be:

  /// remove a specific [Uri] and the corresponding [Page]
  void removeUri(Uri uri) {
    final index = _uris.lastIndexOf(uri);   <--- CHANGE HERE
    if (index != -1) {
      final page = _pages.removeAt(index);
      final uri = _uris.removeAt(index);
      if (kIsWeb) {
        VxNav.replaceUrl(uri);
      }
      if (observers != null) {
        for (final observer in observers!) {
          observer.didChangeRoute(uri, page, "pop");
        }
      }
      notifyListeners();
    }
  }

This because into a long stack we can have also the same uri into the stack and usually we need to remove the last page from the stack and not the first stacked element.

Regards.