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

Future<T?> push<T extends Object?, R extends Object?>(
  1. dynamic route, {
  2. String? name,
  3. Map<String, dynamic>? arguments,
  4. Flag flag = Flag.none,
  5. RoutePredicate? predicate,
  6. R? result,
  7. AnimType type = AnimType.slideLeft,
})

Implementation

Future<T?> push<T extends Object?, R extends Object?>(
  dynamic route, {
  String? name,
  Map<String, dynamic>? arguments,
  Flag flag = Flag.none,
  RoutePredicate? predicate,
  R? result,
  AnimType type = AnimType.slideLeft,
}) {
  if (flag == Flag.replacement) {
    if (route is String) {
      return Navigator.pushReplacementNamed(
        context,
        route,
        result: result,
        arguments: arguments,
      );
    } else if (route is Widget) {
      return Navigator.pushReplacement(
        context,
        result: result,
        AppRoute<T>(
          name: name,
          arguments: arguments,
          child: route,
        ),
      );
    } else {
      return Navigator.pushNamed(context, "error");
    }
  } else if (flag == Flag.clear) {
    if (route is String) {
      return Navigator.pushNamedAndRemoveUntil(
        context,
        route,
        predicate ?? (value) => false,
        arguments: arguments,
      );
    } else if (route is Widget) {
      return Navigator.pushAndRemoveUntil(
          context,
          AppRoute<T>(
            name: name,
            arguments: arguments,
            child: route,
          ),
          predicate ?? (route) => false);
    } else {
      return Navigator.pushNamed(context, "error");
    }
  } else {
    if (route is String) {
      return Navigator.pushNamed(
        context,
        route,
        arguments: arguments,
      );
    } else if (route is Widget) {
      return Navigator.push(
        context,
        AppRoute<T>(
          name: name,
          arguments: arguments,
          child: route,
        ),
      );
    } else {
      return Navigator.pushNamed(context, "error");
    }
  }
}