pushNamed<T> method

Future<T> pushNamed<T>(
  1. String page, {
  2. dynamic arguments,
  3. Map<String, String>? parameters,
})

Implementation

Future<T> pushNamed<T>(
  String page, {
  dynamic arguments,
  Map<String, String>? parameters,
}) async {
  if (parameters != null) {
    final uri = Uri(path: page, queryParameters: parameters);
    page = uri.toString();
    print('toNamed with parameters, full page path is $page');
  }
  print('toNamed with page: $page');
  final decoder = Muffin.routeTree.matchRoute(page, arguments: arguments);
  decoder.replaceArguments(arguments);

  print('page path match route, get decoder: $decoder');
  final completer = Completer<T>();

  ///find page in Flutter
  if (decoder.currentRoute != null) {
    RouteConfig routeConfig = RouteConfig(
      currentTreeBranch: decoder.treeBranch,
      location: page,
      state: null,
    );

    ///set to current route
    _callbacks[_history.last] = completer;
    await _pushHistory(routeConfig);
  } else {
    /// found in native
    bool find = false;
    if (multiple) {
      find = await NavigatorChannel.pushNamed(page, arguments);
      print('not found in Flutter, find int native $find');
    }
    if (!find) {
      ///will show not found
      RouteConfig notFound = RouteConfig(
        currentTreeBranch: [notFoundRoute],
        location: page,
        state: null,
      );
      _callbacks[_history.last] = completer;
      await _pushHistory(notFound);
    }
  }
  return completer.future;
}