navigateTo<T extends Object?> method

  1. @override
Future<T?> navigateTo<T extends Object?>({
  1. required String location,
  2. Object? arguments,
  3. List<Destination>? history,
})
override

Navigate to the following location.

location to navigate to. Must be unique in the current navigation stack.

arguments to pass at the location.

Implementation

@override
Future<T?> navigateTo<T extends Object?>({
  required final String location,
  final Object? arguments,
  final List<Destination>? history,
}) async {
  assert(location.trim().isNotEmpty, 'destination location is empty');

  if (history != null && history.isNotEmpty) {
    final List<DBPage> newPages = await _pageBuilders.buildStack(history);

    _pages.addAll(newPages);
  }

  final Destination destination = Destination(
    path: location,
    metadata: DestinationMetadata(
      arguments: arguments,
      history: _pages.map((DBPage page) => page.destination).toList(),
    ),
  );

  final DBPage? newPage = await _pageBuilders.getPage(destination);

  if (newPage == null) {
    throw PageNotFoundException(destination);
  }

  _pages.add(newPage);

  final Completer<T?> popTracker = Completer<T?>();
  _popResultTracker[destination.path] = popTracker;

  notifyListeners();

  if (history != null && history.isNotEmpty) {
    final Completer<T?> topPagePopTracker = Completer<T?>();
    _popResultTracker[history.first.path] = topPagePopTracker;

    final T? result = await topPagePopTracker.future;
    return result;
  }

  final T? result = await popTracker.future;

  return result;
}