Reputation: 61
I have a problem, I'm using GetX in my Flutter Application. I need to use nested navigation cause I'm using BottomNavigationBar. First I have a Navigator Widget, the problem is when the Get.toNamed method is called and the onGenerateRoute is not executing.
This is my code
class NavigatorPage extends GetWidget<NavigatorController> {
NavigatorPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final List<Widget> pages = [
Navigator(
key: Get.nestedKey(2), // create a key by index
onGenerateRoute: (settings) {
if (settings.name == VozComercialRoutes.home) {
return GetPageRoute(
page: () => HomePage(), binding: HomePageBinding());
} else if (settings.name == VozComercialRoutes.listaRegistros) {
return GetPageRoute(
page: () => ListaRegistrosPage(),
binding: ListaRegistrosBinding());
}
}),
Navigator(
key: Get.nestedKey(2), // create a key by index
onGenerateRoute: (settings) {
if (settings.name == VozComercialRoutes.home) {
return GetPageRoute(
page: () => HomePage(), binding: HomePageBinding());
} else if (settings.name == VozComercialRoutes.listaRegistros) {
return GetPageRoute(
page: () => ListaRegistrosPage(),
binding: ListaRegistrosBinding());
}
}),
];
return Scaffold(
extendBodyBehindAppBar: true,
appBar: CustomAppBar(),
body: PageView(
onPageChanged: controller.changePage,
controller: controller.pageController,
children: pages,
),
bottomNavigationBar: Obx(() => BottomNavigationBar(
onTap: controller.changePage,
currentIndex: controller.tabIndex.value,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'home',
),
BottomNavigationBarItem(
icon: Icon(Icons.download),
label: 'download',
),
])),
);
}
}
The navigate code is
Get.toNamed(VozComercialRoutes.registro, arguments: registro);
I have tried with the following code and it works, but I want to use GetX
Navigator.pushNamed(VozComercialRoutes.registro)
Thanks
Upvotes: 4
Views: 4305
Reputation: 2788
try
Get.toNamed(
VozComercialRoutes.registro,
arguments: registro,
// the same id as the navigation key
id: "2"
);
Upvotes: 2