skip to Main Content

I have a working repsitory on Github for this use case. The repository is working well. What I wanted to show is that I used that kind of code to run Flutter Web on website, but I cannot share the repository code as it is meant for company’s admin to run. There are a lot of secret information on the website.

My problem is a few links when get clicked, they cannot go to designation web page. It is like the link doesn’t work at all. In my case, I use

Get.rootDelegate.offNamed(Routes.LISTALBUMS);

I placed this code inside a few pages, and all of them don’t work. I changed it into Stateful Widget and add initState() to receive parameters from previous page, but it doesn’t work either. The link to this page doesn’t work at all.

Get.rootDelegate.parameters;

Meanwhile other web pages with same functional Widget do work. I used this code:

Get.rootDelegate.offNamed(Routes.REGISTEREDMENU);

This is some part the code:

//main.dart
return GetMaterialApp.router(
   key: Get.key,
   useInheritedMediaQuery: true,
   debugShowCheckedModeBanner: false,
   smartManagement: SmartManagement.full,
   defaultTransition: Transition.noTransition,
   getPages: AppPages.pages,
   routerDelegate: AppRouterDelegate(),
   routeInformationParser: GetInformationParser(
     initialRoute: Routes.HOME,
   ),
);

//routes.dart
class AppRouterDelegate extends GetDelegate {
  GetNavConfig get prevRoute => history.length < 2 ? history.last : history[history.length - 2];

  @override
  Future<GetNavConfig> popHistory() async {
    final result = prevRoute;
    Get.rootDelegate.offNamed(prevRoute.currentPage!.name);
    return result;
  }
  
  @override
  Widget build(BuildContext context) {
    return Navigator(
      reportsRouteUpdateToEngine: true,
      onPopPage: (route, result) => route.didPop(result),
      pages: currentConfiguration != null ? [currentConfiguration!.currentPage!] : [GetNavConfig.fromRoute(Routes.HOME)!.currentPage!],
    );
  }
}

2

Answers


  1. Chosen as BEST ANSWER

    After making some trial-error test for a few days, I found out that GetX Routing is still lacking a lot of things compared to Flutter Go Router. Finally, I know how I can combine GetMaterialApp.router with Flutter Go Router.

    This is the code:

    //on router.dart
    final GoRouter router = GoRouter(
      navigatorKey: Get.key,  //Important, add this code
      routes: <RouteBase>[
        GoRoute(
          path: '/',
          builder: (BuildContext context, GoRouterState state) {
            return HomePage();
          },
          routes: <RouteBase>[
            GoRoute(
              path: 'login',
              builder: (BuildContext context, GoRouterState state) {
                return SignInMobile();
              },
            ),
            GoRoute(
              path: 'had',
              builder: (BuildContext context, GoRouterState state) {
                return HaDPage();
              },
            ),
          ],
       ],
    );
    
    //on main.dart
        return GetMaterialApp.router(
          key: Get.key,
          useInheritedMediaQuery: true,
          debugShowCheckedModeBanner: false,
          smartManagement: SmartManagement.full,
          defaultTransition: Transition.noTransition,
          routerDelegate: router.routerDelegate,
          routeInformationParser: router.routeInformationParser,
          routeInformationProvider: router.routeInformationProvider,
        );


  2. I have found the correct answer.

    When I tried to send parameters into another page using

    Get.rootDelegate.offNamed(
      Routes.ADDALBUM, 
      parameters: {
        active: false,
        rejected: false, 
        editor: true
    });

    I forgot that I had 3 bool variables which I did not convert to string. So, the rule to send parameters in Getx Routing is all kinds of variables must be converted to string. This rule also valids for number, i.e.: int, double, etc. It should be something like this:

    Get.rootDelegate.offNamed(
      Routes.ADDALBUM, 
      parameters: {
        active: false.toString(),
        rejected: false.toString(), 
        editor: true.toString(),
      });

    Problem is solved.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search