0

I Have A fluter web project in which I am using the go router package I have given "/" route to HomePage I also have a logo in my app bar I want when user to click on logo then he or she should redirect to home page for which I have given the logo image a gesture detector with on tap with this command GoRouter.of(context).push("/"); but when I click on this it does not load the full page instead loading only some content which is not from firebase. all the contact from firebase is not be shown.

class Prasthan extends StatelessWidget {
  const Prasthan({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
        debugShowCheckedModeBanner: false,
        title: 'Prasthan',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        routeInformationParser: MyAppRouter().router.routeInformationParser,
        routerDelegate: MyAppRouter().router.routerDelegate);
  }
}

this is my app router class

class MyAppRouter {
  GoRouter router = GoRouter(
      routes: [
        GoRoute(
            name: "Home",
            path: "/",
            pageBuilder: (context, state) {
              return MaterialPage(child: HomePage());
            }),
        GoRoute(
            name: MyRoutes.aboutUs,
            path: "/About",
            pageBuilder: (context, state) {
              return MaterialPage(child: AboutUs());
            }),
        GoRoute(
            name: MyRoutes.contactUs,
            path: "/Contact",
            pageBuilder: (context, state) {
              return MaterialPage(child: ContactUs());
            }),
        GoRoute(
            name: MyRoutes.termsandpolicies,
            path: "/Terms-And-Policies",
            pageBuilder: (context, state) {
              return MaterialPage(child: TermsAndConditions());
            }),
        GoRoute(
            name: MyRoutes.hotels,
            path: "/Hotels",
            pageBuilder: (context, state) {
              return MaterialPage(child: hotels);
            }),
        GoRoute(
            name: MyRoutes.destinations,
            path: "/Destinations",
            pageBuilder: (context, state) {
              return MaterialPage(child: location);
            }),
        GoRoute(
            name: MyRoutes.packageView,
            path: "/Packages/:packageid/:packagename",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: PackageView(
                packagename: state.params["packagename"]!,
                packageid: state.params["packageid"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.hotelView,
            path: "/Hotels/:hotelid/:hotelname",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: HotelView(
                hotelname: state.params["hotelname"]!,
                hotelid: state.params["hotelid"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.destinationsView,
            path: "/Destinations/:destinationid/:destinationname",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: DestinationView(
                destinationname: state.params["destinationname"]!,
                destinationid: state.params["destinationid"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.theme,
            path: "/Packages-Theme/:theme",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: PackagesThemeView(
                theme: state.params["theme"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.category,
            path: "/Packages-Category/:label",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: PackagesLabelView(
                label: state.params["label"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.destinationLabel,
            path: "/Destination-Category/:label",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: LocationLabel(
                label: state.params["label"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.charDhamPackages,
            path: "/Char-Dham_Packages/:label1/:label2",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: CharDhamLabelView(
                label1: state.params["label1"]!,
                label2: state.params["label2"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.destinationsPackagedetails,
            path: "/Destination-Packages/:location",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: DestinationAllPackages(
                location: state.params["location"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.destinationsHotelsdetails,
            path: "/Destination-Hotels/:location",
            pageBuilder: (context, state) {
              return MaterialPage(
                  child: DestinationAllHotels(
                location: state.params["location"]!,
              ));
            }),
        GoRoute(
            name: MyRoutes.downloadOurApp,
            path: "/Download-Our-App-Prasthan",
            pageBuilder: (context, state) {
              return MaterialPage(child: DownloadOurApp());
            }),
        GoRoute(
            name: MyRoutes.myAccount,
            path: "/My-Account",
            pageBuilder: (context, state) {
              return MaterialPage(child: MyAccountPage());
            }),
        GoRoute(
            name: MyRoutes.career,
            path: "/Career-Opportunities-With-Prasthan",
            pageBuilder: (context, state) {
              return MaterialPage(child: CareerWithUs());
            }),
      ],
      errorPageBuilder: (context, state) {
        return MaterialPage(child: ErrorPage());
      });
}

this my router constants

class MyRoutes {
  static String logohomeRoute = "LogoHome";
  static String theme = "theme";
  static String category = "label";
  static String destinationLabel = "destination-label";
  static String hotels = "hotels";
  static String destinations = "destinations";
  static String charDhamPackages = "char-dham-yatra-packages";
  static String aboutUs = "about-us";
  static String contactUs = "contact-us";
  static String termsandpolicies = "terms-and-policies";
  static String packageView = "package-details/id";
  static String destinationsView = "destinations-details";
  static String destinationsPackagedetails = "destinations-package-details";
  static String destinationsHotelsdetails = "destinations-hotel-details";
  static String hotelView = "hotel-details";
  static String myAccount = "my-account";
  static String career = "careert";
  static String downloadOurApp = "download-our-app";
}

and I am trying to navigate like this

const mainLogo = MainLogo();

class MainLogo extends StatefulWidget {
  const MainLogo({super.key});

  @override
  State<MainLogo> createState() => _MainLogoState();
}

class _MainLogoState extends State<MainLogo> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: GestureDetector(
        onTap: () async {
          GoRouter.of(context).push("/");
        },
        child: mainLogoImage,
      ),
    );
  }
}

const Image mainLogoImage = Image(
  image: ExactAssetImage("images/Prasthan.png"),
  width: 170,
  height: 170,
);

0 Answers0