You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION. Fill in the template. Issues that do not respect the model will be closed.
Describe the bug
Using multiple navigators with bottom navigation bar, Get.back works fine when the route is generated through onGenerateRoute but does not work when the routes are generated through onGenerateInitialRoutes.
Reproduction code
NOTE: THIS IS MANDATORY, IF YOUR ISSUE DOES NOT CONTAIN IT, IT WILL BE CLOSED PRELIMINARY)
example:
voidmain() {
runApp(
GetMaterialApp(
title:"Nested Routing",
initialRoute:Routes.BASE,
getPages: [
GetPage(
name:Routes.BASE,
page: () =>constBaseView(),
binding:BaseBinding(),
),
],
),
);
}
classBaseViewextendsGetView<BaseController> {
constBaseView({super.key});
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
body:Obx(() =>
controller.widgetOptions.elementAt(controller.selectedIndex.value)),
bottomNavigationBar:Obx(
() =>BottomNavigationBar(
type:BottomNavigationBarType.fixed,
items:const<BottomNavigationBarItem>[
BottomNavigationBarItem(
icon:Icon(Icons.home),
label:'Home',
),
BottomNavigationBarItem(
icon:Icon(Icons.person),
label:'Profile',
),
],
currentIndex: controller.selectedIndex.value,
onTap: controller.onItemTapped,
),
),
);
}
}
classBaseControllerextendsGetxController {
staticBaseControllerget to =>Get.find<BaseController>();
RxInt selectedIndex =0.obs;
lateList<Widget> widgetOptions;
BaseController() {
widgetOptions =<Widget>[
constHomeNavigator(),
constProfileWrapper(),
];
}
voidonItemTapped(int index) {
selectedIndex.value = index;
}
}
classHomeNavigatorextendsStatelessWidget {
constHomeNavigator({
super.key,
});
@overrideWidgetbuild(BuildContext context) {
Get.put<HomeNavigatorController>(HomeNavigatorController(),
permanent:true);
returnGetBuilder<HomeNavigatorController>(
builder: (controller) {
returnNavigator(
key:Get.nestedKey(nestedNavigationHomeId),
initialRoute:Routes.HOME,
onGenerateInitialRoutes: controller.onGenerateInitalRoutes,
onGenerateRoute: controller.onGenerateRoute,
);
},
);
}
}
classHomeNavigatorControllerextendsGetxController {
staticHomeNavigatorControllerget to =>Get.find<HomeNavigatorController>();
// Stack of route names to manage the navigation historyfinalList<String> _routeStack = [];
List<String> get routeStack => _routeStack;
voidpushRoute(String routeName) {
_routeStack.add(routeName);
}
List<Route<dynamic>> get generateRoutes => routeStack.map(
(route) {
returnGetPageRoute(
routeName: route,
page: () {
switch (route) {
caseRoutes.HOME:returnconstHomeView();
caseRoutes.DETAILS:returnconstDetailsView();
default:returnconstHomeView();
}
},
binding: route ==Routes.HOME?HomeBinding()
: route ==Routes.DETAILS?DetailsBindings()
:null,
);
},
).toList();
List<Route<dynamic>> onGenerateInitalRoutes(
NavigatorState state, String initialRoute) {
return routeStack.isNotEmpty
? generateRoutes
:Navigator.defaultGenerateInitialRoutes(state, initialRoute);
}
Route<dynamic>?onGenerateRoute(RouteSettings settings) {
if (settings.name ==Routes.HOME) {
routeStack.add(Routes.HOME);
returnGetPageRoute(
routeName:Routes.HOME,
page: () =>constHomeView(),
binding:HomeBinding(),
);
}
if (settings.name ==Routes.DETAILS) {
routeStack.add(Routes.DETAILS);
returnGetPageRoute(
routeName:Routes.DETAILS,
page: () =>constDetailsView(),
binding:DetailsBindings(),
);
}
returnnull;
}
}
classProfileWrapperextendsStatelessWidget {
constProfileWrapper({super.key});
@overrideWidgetbuild(BuildContext context) {
returnNavigator(
key:Get.nestedKey(nestedNavigationProfileId),
initialRoute:Routes.PROFILE,
onGenerateRoute: (routeSettings) {
if (routeSettings.name ==Routes.PROFILE) {
returnGetPageRoute(
routeName:Routes.PROFILE,
title:"Profile Page",
page: () =>constProfileView(),
binding:ProfileBinding());
}
returnnull;
},
);
}
}
classHomeViewextendsGetView<HomeController> {
constHomeView({super.key});
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
title:constText('HomeView'),
centerTitle:true,
),
body:Center(
child:Column(
mainAxisAlignment:MainAxisAlignment.center,
children: [
TextButton(
onPressed: controller.goToDetails,
child:constText("Go to details"),
),
],
),
),
);
}
}
classProfileViewextendsGetView<ProfileController> {
constProfileView({super.key});
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
title:constText('ProfileView'),
centerTitle:true,
),
body:Center(
child:TextButton(
onPressed: (){},
child:constText("Profile Page"),
),
),
);
}
}
classProfileControllerextendsGetxController {
voidgoToSettingPage() {
}
}
classHomeControllerextendsGetxController {
voidgoToDetails() {
Get.toNamed(Routes.DETAILS, id: nestedNavigationHomeId);
}
}
classProfileBindingextendsBindings {
@overridevoiddependencies() {
Get.lazyPut<ProfileController>(() =>ProfileController());
}
}
classHomeBindingextendsBindings {
@overridevoiddependencies() {
Get.lazyPut<HomeController>(() =>HomeController());
}
}
classDetailsViewextendsGetView<DetailsController> {
constDetailsView({super.key});
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
appBar:AppBar(
title:constText('Details view'),
centerTitle:true,
leading:IconButton(
onPressed: controller.goBack,
icon:constIcon(Icons.arrow_back),
),
),
body:Center(
child:TextButton(
onPressed: (){},
child:TextButton(
onPressed: controller.goToSearch,
child:constText("Details Page"),
),
),
),
);
}
}
classDetailsControllerextendsGetxController {
// This is supposed to go through home navigatorvoidgoBack() {
Get.back(id: nestedNavigationHomeId);
}
}
classDetailsBindingsextendsBindings {
@overridevoiddependencies() {
Get.lazyPut<DetailsController>(() =>DetailsController());
}
}
**ToReproduce**Steps to reproduce the behavior:1. Go to DetailsView2. Change tab to Profile3. Change tab back to Home4. Go back
5. Change tab to profile again
6. Change tab back to Home**Expected behavior**Itis supposed to be onHomePage rather than Details**Screenshots**If applicable, add screenshots to help explain your problem.
**FlutterVersion:**3.24.0**GetxVersion:**get:^4.6.6**Describeon which device you found the bug:**Iphone15 simulator
**Minimal reproduce code**Provide a minimum reproduction code for the problem
The text was updated successfully, but these errors were encountered:
ATTENTION: DO NOT USE THIS FIELD TO ASK SUPPORT QUESTIONS. USE THE PLATFORM CHANNELS FOR THIS. THIS SPACE IS DEDICATED ONLY FOR BUGS DESCRIPTION.
Fill in the template. Issues that do not respect the model will be closed.
Describe the bug
Using multiple navigators with bottom navigation bar, Get.back works fine when the route is generated through onGenerateRoute but does not work when the routes are generated through onGenerateInitialRoutes.
Reproduction code
NOTE: THIS IS MANDATORY, IF YOUR ISSUE DOES NOT CONTAIN IT, IT WILL BE CLOSED PRELIMINARY)
example:
The text was updated successfully, but these errors were encountered: