push<T extends Object?, R extends Object?> method

Future<T?> push<T extends Object?, R extends Object?>(
  1. dynamic route, {
  2. bool? allowSnapshotting,
  3. Curve? animationCurve,
  4. int? animationTime,
  5. int? animationReserveTime,
  6. AnimationType? animationType,
  7. Map<String, dynamic> arguments = const {},
  8. Color? barrierColor,
  9. bool? barrierDismissible,
  10. String? barrierLabel,
  11. bool? fullscreenDialog,
  12. String? name,
  13. Flag? flag,
  14. bool? maintainState,
  15. bool? opaque,
  16. RoutePredicate? predicate,
  17. R? result,
})

Implementation

Future<T?> push<T extends Object?, R extends Object?>(
  dynamic route, {
  bool? allowSnapshotting,
  Curve? animationCurve,
  int? animationTime,
  int? animationReserveTime,
  AnimationType? animationType,
  Map<String, dynamic> arguments = const {},
  Color? barrierColor,
  bool? barrierDismissible,
  String? barrierLabel,
  bool? fullscreenDialog,
  String? name,
  Flag? flag,
  bool? maintainState,
  bool? opaque,
  RoutePredicate? predicate,
  R? result,
}) {
  if (route is String) {
    arguments.putIfAbsent("__app_route_config__", () {
      return AppRouteConfig(
        allowSnapshotting: allowSnapshotting,
        animationCurve: animationCurve,
        animationTime: animationTime,
        animationReserveTime: animationReserveTime,
        animationType: animationType,
        barrierColor: barrierColor,
        barrierDismissible: barrierDismissible,
        barrierLabel: barrierLabel,
        fullscreenDialog: fullscreenDialog,
        maintainState: maintainState,
        opaque: opaque,
      );
    });

    if (flag == Flag.replacement) {
      return Navigator.pushReplacementNamed(
        context,
        route,
        result: result,
        arguments: arguments,
      );
    } else if (flag == Flag.clear) {
      return Navigator.pushNamedAndRemoveUntil(
        context,
        route,
        predicate ?? (value) => false,
        arguments: arguments,
      );
    } else {
      return Navigator.pushNamed(
        context,
        route,
        arguments: arguments,
      );
    }
  } else if (route is Widget) {
    AppRoute<T> mRoute = AppRoute<T>(
      name: name,
      allowSnapshotting: allowSnapshotting ?? true,
      animationTime: animationTime ?? 500,
      animationReserveTime: animationReserveTime,
      animationType: animationType ?? AnimationType.slideRight,
      arguments: arguments,
      barrierColor: barrierColor,
      barrierDismissible: barrierDismissible ?? false,
      barrierLabel: barrierLabel,
      animationCurve: animationCurve ?? Curves.decelerate,
      fullscreenDialog: fullscreenDialog ?? false,
      maintainState: maintainState ?? true,
      opaque: opaque ?? true,
      builder: (_) => route,
    );

    if (flag == Flag.replacement) {
      return Navigator.pushReplacement(
        context,
        result: result,
        mRoute,
      );
    } else if (flag == Flag.clear) {
      return Navigator.pushAndRemoveUntil(
        context,
        mRoute,
        predicate ?? (route) => false,
      );
    } else {
      return Navigator.pushNamed(context, "error");
    }
  } else {
    return Navigator.pushNamed(context, "error");
  }
}