GetX Get.toNamed() 忽略 Navigator 上的 onGenerateRoute
GetX Get.toNamed() is ignoring onGenerateRoute on Navigator
我有问题,我在我的 Flutter 应用程序中使用 GetX。我需要使用嵌套导航,因为我使用的是 BottomNavigationBar。
首先我有一个 Navigator Widget,问题是当 Get.toNamed 方法被调用并且 onGenerateRoute 没有执行时。
这是我的代码
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',
),
])),
);
}
}
导航代码是
Get.toNamed(VozComercialRoutes.registro, arguments: registro);
我已经尝试使用以下代码并且它有效,但我想使用 GetX
Navigator.pushNamed(VozComercialRoutes.registro)
谢谢
尝试
Get.toNamed(
VozComercialRoutes.registro,
arguments: registro,
// the same id as the navigation key
id: "2"
);
我有问题,我在我的 Flutter 应用程序中使用 GetX。我需要使用嵌套导航,因为我使用的是 BottomNavigationBar。 首先我有一个 Navigator Widget,问题是当 Get.toNamed 方法被调用并且 onGenerateRoute 没有执行时。
这是我的代码
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',
),
])),
);
}
}
导航代码是
Get.toNamed(VozComercialRoutes.registro, arguments: registro);
我已经尝试使用以下代码并且它有效,但我想使用 GetX
Navigator.pushNamed(VozComercialRoutes.registro)
谢谢
尝试
Get.toNamed(
VozComercialRoutes.registro,
arguments: registro,
// the same id as the navigation key
id: "2"
);