toNamed<T> method

Future<T> toNamed<T>(
  1. String page,
  2. {dynamic arguments,
  3. int id,
  4. bool preventDuplicates = true}

Navigation.pushNamed() shortcut.

Pushes a new named page to the stack.

It has the advantage of not needing context, so you can call from your business logic.

You can send any type of value to the other route in the arguments.

id is for when you are using nested navigation, as explained in documentation

By default, GetX will prevent you from push a route that you already in, if you want to push anyway, set preventDuplicates to false

Note: Always put a slash on the route ('/page1'), to avoid unnexpected errors


Future<T> toNamed<T>(
  String page, {
  dynamic arguments,
  int id,
  bool preventDuplicates = true,
}) {
  if (preventDuplicates && page == currentRoute) {
    return null;
  return global(id)?.currentState?.pushNamed(page, arguments: arguments);