router top-level property

GoRouter router
final

Implementation

final router = GoRouter(
  navigatorKey: navigatorKey,
  initialLocation: Routes.LANDING,
  routes: [
    GoRoute(
      name: Routes.HOME,
      path: Routes.HOME,
      builder: (context, state) {
        Get.put(HomeController());
        return HomeView();
      },
    ),
    GoRoute(
      name: Routes.SIGNIN,
      path: Routes.SIGNIN,
      builder: (context, state) => SignInView(),
    ),
    GoRoute(
      name: Routes.FORGET_PASSWORD,
      path: Routes.FORGET_PASSWORD,
      builder: (context, state) => const ForgetPasswordView(),
    ),
    GoRoute(
      name: Routes.SUBSCRIPTION,
      path: Routes.SUBSCRIPTION,
      builder: (context, state) {
        Get.put(SubscriptionController());
        return SubscriptionView();
      },
    ),
    GoRoute(
      name: Routes.SUBSCRIPTION_PAYMENT,
      path: Routes.SUBSCRIPTION_PAYMENT,
      builder: (context, state) {
        Get.put(SubscriptionController());
        return SubscriptionPaymentView();
      },
    ),
    GoRoute(
      name: Routes.FAQ,
      path: Routes.FAQ,
      builder: (context, state) {
        final flag = state.uri.queryParameters['flag'] ?? 'false';
        Get.put(ContactUsController());
        return ContactUsView(flag: flag);
      },
    ),
    GoRoute(
      name: Routes.PROFILE,
      path: Routes.PROFILE,
      builder: (context, state) {
        Get.put(ProfileController());
        return ProfileView();
      },
    ),
    GoRoute(
      name: Routes.FLIGHT_SEARCH,
      path: Routes.FLIGHT_SEARCH,
      builder: (context, state) {
        Get.put(FlightSearchController());
        return FlightSearchView();
      },
    ),
    GoRoute(
      name: Routes.CHOOSE_PAYMENT,
      path: Routes.CHOOSE_PAYMENT,
      builder: (context, state) {
        Get.put(PaymentController());
        return const ChoosePaymentMethod();
      },
    ),
    GoRoute(
      name: Routes.TOP_FLIGHTS,
      path: Routes.TOP_FLIGHTS,
      builder: (context, state) {
        Get.put(TopFlightsController());
        return TopFlightsView();
      },
    ),
    GoRoute(
      name: Routes.BOOKING_CONFIRMATION,
      path: Routes.BOOKING_CONFIRMATION,
      builder: (context, state) {
        Get.put(BookingConfirmationController());
        return const BookingConfirmationView();
      },
    ),
    GoRoute(
      name: Routes.NEO_DASHBOARD,
      path: Routes.NEO_DASHBOARD,
      builder: (context, state) {
        final controller = Get.put(NeoDashboardController());
        controller.selectedIndex.value = 0;
        return NeoDashboardView();
      },
    ),
    GoRoute(
      name: Routes.DASHBOARD_OVERVIEW,
      path: Routes.DASHBOARD_OVERVIEW,
      builder: (context, state) {
        final controller = Get.put(NeoDashboardController());
        controller.selectedIndex.value = 0;
        return NeoDashboardView();
      },
    ),
    GoRoute(
      name: Routes.DASHBOARD_FLIGHTS_SEARCHED,
      path: Routes.DASHBOARD_FLIGHTS_SEARCHED,
      builder: (context, state) {
        final controller = Get.put(NeoDashboardController());
        controller.selectedIndex.value = 1;
        controller.setSelectedIndex(0);
        return NeoDashboardView();
      },
    ),
    GoRoute(
      name: Routes.DASHBOARD_FLGIHTS_BOOKED,
      path: Routes.DASHBOARD_FLGIHTS_BOOKED,
      builder: (context, state) {
        final controller = Get.put(NeoDashboardController());
        controller.selectedIndex.value = 1;
        controller.setSelectedIndex(1);
        return NeoDashboardView();
      },
    ),
    GoRoute(
      name: Routes.DASHBOARD_RATE_REQUESTS,
      path: Routes.DASHBOARD_RATE_REQUESTS,
      builder: (context, state) {
        final controller = Get.put(NeoDashboardController());
        controller.selectedIndex.value = 1;
        controller.setSelectedIndex(2);
        return NeoDashboardView();
      },
    ),
    GoRoute(
      name: Routes.DASHBOARD_BENEFITS,
      path: Routes.DASHBOARD_BENEFITS,
      builder: (context, state) {
        final controller = Get.put(NeoDashboardController());
        controller.selectedIndex.value = 2;
        return NeoDashboardView();
      },
    ),
    GoRoute(
      name: Routes.DASHBOARD_PAYMENTS,
      path: Routes.DASHBOARD_PAYMENTS,
      builder: (context, state) {
        final controller = Get.put(NeoDashboardController());
        controller.selectedIndex.value = 3;
        return NeoDashboardView();
      },
    ),
    GoRoute(
      name: Routes.NEO_ONE_PAYMENT,
      path: Routes.NEO_ONE_PAYMENT,
      builder: (context, state) {
        Get.put(NeoOnePaymentController());
        return const NeoOnePayment();
      },
    ),
    GoRoute(
      name: Routes.THE_CLUB,
      path: Routes.THE_CLUB,
      builder: (context, state) {
        Get.put(TheClubController());
        return const TheClubView();
      },
    ),
    GoRoute(
      name: Routes.GLOBAL_IMPACT,
      path: Routes.GLOBAL_IMPACT,
      builder: (context, state) {
        Get.put(GlobalImpactController());
        return const GlobalImpactView();
      },
    ),
    GoRoute(
      name: Routes.LOYALTY_NEO_MILES,
      path: Routes.LOYALTY_NEO_MILES,
      builder: (context, state) {
        Get.put(LoyaltyNeoMilesController());
        return LoyaltyNeoMilesView();
      },
    ),
    GoRoute(
      name: Routes.AI_NAVIGATOR,
      path: Routes.AI_NAVIGATOR,
      builder: (context, state) {
        Get.put(AiNavigatorController());
        return const AiNavigatorView();
      },
    ),
    GoRoute(
      name: Routes.LANDING,
      path: Routes.LANDING,
      builder: (context, state) {
        Get.put(LandingController());
        return LandingView();
      },
    ),
    GoRoute(
      name: Routes.SEARCH_CREDIT,
      path: Routes.SEARCH_CREDIT,
      builder: (context, state) {
        Get.put(SearchCreditController());
        return SearchCreditView();
      },
    ),
    GoRoute(
      name: Routes.PAYMENT_SUCCESS,
      path: Routes.PAYMENT_SUCCESS,
      builder: (context, state) {
        Get.put(PaymentStatusController());
        return PaymentSuccessView();
      },
    ),
    GoRoute(
      name: Routes.PAYMENT_FAILURE,
      path: Routes.PAYMENT_FAILURE,
      builder: (context, state) {
        Get.put(PaymentStatusController());
        return PaymentFailureView();
      },
    ),
    GoRoute(
      name: Routes.PRIVACY_POLICY,
      path: Routes.PRIVACY_POLICY,
      builder: (context, state) {
        return const PolicyPage();
      },
    ),
    GoRoute(
      name: Routes.BANK_PAYMENT,
      path: Routes.BANK_PAYMENT,
      builder: (context, state) {
        Get.put(PaymentController());
        return BankPaymentView();
      },
    ),
    GoRoute(
      name: Routes.FEEDBACK_FORM,
      path: Routes.FEEDBACK_FORM,
      builder: (context, state) {
        return FeedbackFormView();
      },
    ),
    GoRoute(
      name: Routes.MORE,
      path: Routes.MORE,
      builder: (context, state) {
        return const MoreView();
      },
    ),
    GoRoute(
      name: Routes.RATE_CONFIRMATION_VIEW,
      path: Routes.RATE_CONFIRMATION_VIEW,
      builder: (context, state) {
        Get.put(PaymentController());
        return RateConfirmationView();
      },
    ),
    GoRoute(
      name: Routes.RATE_REQUEST_VIEW,
      path: Routes.RATE_REQUEST_VIEW,
      builder: (context, state) {
        Get.put(PaymentController());
        return RateRequestView();
      },
    ),
    GoRoute(
      name: Routes.DEEP_SEARCH,
      path: Routes.DEEP_SEARCH,
      builder: (context, state) {
        Get.put(DeepSearchController());
        return DeepSearchView();
      },
    ),
    GoRoute(
      name: Routes.SHARE_INVITATION,
      path: Routes.SHARE_INVITATION,
      builder: (context, state) {
        Get.put(ShareInvitationController());
        return const ShareInvitationPage();
      },
    ),
  ],
  redirect: (context, state) {
    final url = window.location.href;
    final page = url.replaceFirst(window.location.origin, '');

    if (page.startsWith('/r/')) {
      Preferences.storeRefCode(page.replaceFirst('/r/', ''));
      final uri = Uri.parse(url);
      final segments = uri.pathSegments;
      if (segments.length >= 2 && segments[segments.length - 2] == 'r') {
        Preferences.storeRefCode(segments[segments.length - 1]);
      }
      return Routes.LANDING;
    }


    if (!doesRouteExists(page)) {
      return null;
    }

    if (doesRequireAuthentication(page)) {
      if (!Get.find<AuthenticationController>().isLoggedIn) {
        return Routes.SIGNIN;
      }
    }

    return null;
  },
  errorBuilder: (context, state) => ErrorPage(error: state.error),
);