navigateToPage method

Future<bool> navigateToPage(
  1. Object page,
  2. StartupPageCompleter completer
)

Navigate to page.

When using StandardAppPlugin, navigation to the page defined in StandardMaterialApp.pages or StandardCupertinoApp.pages can be achieved by passing the page's Type. If you want custom navigation, implement a Plugin that overrides StartupNavigatorMixin.startupNavigateToPage.

Please pass completer to every page navigated to using this method. When using StandardAppPlugin, this would be StandardPage.pageData.

By calling completer within the page, the internal processes are executed and the Future of this method returns true. If another state switches without calling completer, the Future returns false.

Implementation

Future<bool> navigateToPage(
  Object page,
  StartupPageCompleter completer,
) async {
  final tPlugin = startupSequence._startupNavigator;
  assert(tPlugin != null);

  await startupSequence.waitForSplash();

  if (!this()) {
    throw LogicStateNotCurrent(this);
  }
  assert(
    _navigateCompleter == null || _navigateCompleter?.isCompleted == true,
  );
  final tCompleter = Completer<bool>();
  _navigateCompleter = tCompleter;

  backAllowed = true;
  tPlugin?.startupNavigateToPage(page, (result) {
    if (tCompleter.isCompleted) {
      return;
    }

    tCompleter.complete(true);
    completer(result);
  });

  return tCompleter.future;
}