forwardAndReplace static method

Future forwardAndReplace(
  1. Widget widget,
  2. {String? name}
)

Forward navigation and replace current one, it's similar to Navigator.of(context).pushAndReplace

Implementation

static Future<dynamic> forwardAndReplace(Widget widget,
    {String? name}) async {
  if (onBeforePush != null) {
    onBeforePush!(widget);
  }

  dynamic routeFuture = await navigatorKey.currentState!.pushReplacement(
    useCupertinoTransition
        ? CupertinoPageRoute(
            builder: (_) => widget,
            settings: RouteSettings(name: name ?? widget.toString()),
          )
        : MaterialPageRoute(
            builder: (_) => widget,
            settings: RouteSettings(name: name ?? widget.toString()),
          ),
  );

  if (onAfterPush != null) {
    onAfterPush!(widget);
  }
  return routeFuture;
}