setNewRoutePath method

  1. @override
Future<void> setNewRoutePath(
  1. RouteStack configuration
)
override

Called by the Router when the Router.routeInformationProvider reports that a new route has been pushed to the application by the operating system.

Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to schedule a build.

Implementation

@override
Future<void> setNewRoutePath(RouteStack configuration) {
  _checkAlive();
  final source = _observing ? currentRoute : null;
  final incoming = configuration.locations;
  if (incoming.length == 1 && incoming.single.id == null) {
    try {
      final uri = parseRouteUri(incoming.single.uri.toString());
      _replaceStack(
          _canonicalStack(uri, arguments: incoming.single.arguments));
    } catch (_) {
      _replaceStack([
        _entry(incoming.single.uri.toString(),
            arguments: incoming.single.arguments)
      ]);
    }
  } else {
    final entries = <_Entry>[];
    for (final location in incoming) {
      final existing = _entries.where((entry) =>
          entry.location.id == location.id &&
          entry.location.uri == location.uri);
      if (existing.isNotEmpty) {
        final entry = existing.first;
        // Preserve the pending result and page identity, but honor updated
        // restored arguments so argument-dependent checks run again.
        entry.location = location;
        entries.add(entry);
      } else {
        entries.add(_entry(location.uri.toString(),
            arguments: location.arguments, id: location.id));
      }
    }
    _replaceStack(entries);
  }
  _record(NavigationAction.restore, source: source, subject: _entries.last);
  _titleObserver?.refreshAfterBuild();
  notifyListeners();
  return SynchronousFuture(null);
}