goTo method

Future<void> goTo(
  1. Destination<DestinationParameters> destination
)

Navigates to specified destination.

First, searches the navigation scheme for proper navigator for the destination. If found, uses the navigator's goTo method to navigate to the destination. Otherwise throws UnknownDestinationException.

Implementation

Future<void> goTo(Destination destination) async {
  if (currentDestination == destination) {
    Log.d(runtimeType,
        'goTo(): Ignore navigation to $destination. It is already the current destination.');
    return;
  }

  final navigator = findNavigator(destination);
  if (navigator == null) {
    _handleError(destination);
    return SynchronousFuture(null);
  }
  Log.d(runtimeType,
      'goTo(): navigator=${navigator.tag}, destination=$destination, redirectedFrom=${destination.settings.redirectedFrom}, currentDestination=$currentDestination');
  _shouldClose = false;

  final completer = Completer<void>();
  _setupCompleter(destination, completer);

  if (navigator.keepStateInParameters &&
      navigator.stack.isNotEmpty &&
      navigator.currentDestination != destination &&
      destination.settings.reset &&
      _hasStateInParameters(destination)) {
    Log.d(runtimeType, 'goTo(): Restore navigation state');
    _restoreStateFromParameters(destination, navigator);
  } else {
    navigator.goTo(destination);
  }

  return completer.future;
}