back method

Future<bool> back(
  1. dynamic until
)

Implementation

Future<bool> back(dynamic until) async {

  // determine number of pages to go back
  int pages = 0;
  if (until is int) pages = until;
  if (until is String) {
    // match by index
    if (until.startsWith('[') && until.endsWith(']')) {
      int? pageIndex = toInt(until.substring(1, until.length - 1));
      pages = pageIndex != null ? (_pages.length) - pageIndex : -1;
    }

    // match by name
    else {
      if (!until.startsWith("/")) until = "/$until";
      Page? page = _pages.lastWhereOrNull((page) {
        // make sure we leave args off for the comparison
        String name = page.name ?? '';
        return name.split('?')[0] == until;
      });
      if ((page != null) && (_pages.last != page)) {
        pages = _pages.length - _pages.indexOf(page) - 1;
      }
    }
  }

  // go back
  return await _goBack(pages, initiator: back);
}