offNamed<T> method

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

Navigation.pushReplacementNamed() shortcut.

Pop the current named page in the stack and push a new one in its place

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 unexpected errors

Implementation

Future<T?>? offNamed<T>(
  String page, {
  dynamic arguments,
  String? id,
  Map<String, String>? parameters,
}) {
  // if (preventDuplicates && page == currentRoute) {
  //   return null;
  // }

  if (parameters != null) {
    final uri = Uri(path: page, queryParameters: parameters);
    page = uri.toString();
  }
  return searchDelegate(id).offNamed(
    page,
    arguments: arguments,
    id: id,
    // preventDuplicates: preventDuplicates,
    parameters: parameters,
  );
}