1 year ago

#71901

test-img

John Mastri

Persistent Navigation Menu using Flutter GetX Routes

I'd like to use the GetX routing management (getPages) but I don't want to load an entirely new scaffold/page each time the route changes - I'd just like to be able to call functions within the widget/current page itself on a route change.

I've tried many different approaches, my latest:

          GetPage(name: "/:section", page: ()=> Home(), maintainState: true, preventDuplicates: true, binding: HomeBinding())
        ]

and the home class in hopes it would not reload the page and just send the parameter in that I could essentially connect to a function call:

class Home extends StatelessWidget {

  const Home({Key? key}) : super(key: key);


  @override
  Widget build(BuildContext context) {

    if(Get.parameters['section'] != null)
    print(Get.parameters['section']);

    return Scaffold(
        body: Stack(
          children: [
            Padding(
              padding: const EdgeInsets.only(top: 100.0),
              child:
              Obx(() => Stack(
                children: Get.find<HomeController>().stackItems)
              ),
            ),
           Menu()
                ]));
  }

}

This doesn't work as it still reloads the Home() widget each time the route parameter changes.

One of the reasons I am looking to have this seamless functionality is the navigation menu needs to animate open and closed once items are selected. By using the GetX routing, the animation does not play since it is reloading the widget. I want simply update the widget on a route and not load a new page entirely.

flutter

flutter-web

flutter-getx

flutter-routes

0 Answers

Your Answer

Accepted video resources