toNamed<T> method

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

Implementation

Future<T> toNamed<T>(
  String page, {
  dynamic arguments,
  Map<String, String>? parameters,
}) async {
  if (parameters != null) {
    final uri = Uri(path: page, queryParameters: parameters);
    page = uri.toString();
  }

  final decoder = Get.routeTree.matchRoute(page, arguments: arguments);
  decoder.replaceArguments(arguments);

  final completer = Completer<T>();

  if (decoder.route != null) {
    _allCompleters[decoder.route!] = completer;
    await pushHistory(
      GetNavConfig(
        currentTreeBranch: decoder.treeBranch,
        location: page,
        state: null, //TODO: persist state?
      ),
    );

    return completer.future;
  } else {
    ///TODO: IMPLEMENT ROUTE NOT FOUND

    return Future.value();
  }
}