GetX Navigation Issue: Unexpected null value in nested navigation
Problem
I'm experiencing an issue with GetX nested navigation in my Flutter application. When trying to navigate to child routes within my HomeScreen
, I'm getting an "Unexpected null value" error.
The error occurs specifically in the HomeScreen
where I'm using GetRouterOutlet
for nested navigation:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following TypeErrorImpl was thrown building
GetRouterOutlet-[LabeledGlobalKey<NavigatorState>#505e1 Getx nested key: 1]:
Unexpected null value.
The relevant error-causing widget was:
GetRouterOutlet-[LabeledGlobalKey<NavigatorState>#505e1 Getx nested key: 1]
Code Structure
Main App Setup (main.dart
):
return GetMaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: Routes.LOGIN,
getPages: Routes.routes,
defaultTransition: Transition.noTransition,
transitionDuration: Duration.zero,
initialBinding: InitialBinding(),
// ... other configurations
);
Routes Configuration:
static final routes = [
// Auth routes (outer navigation)
GetPage(name: LOGIN, page: () => const LoginScreen()),
// ... other auth routes
// Main app structure (nested navigation)
GetPage(
name: HOME,
page: () => const HomeScreen(),
participatesInRootNavigator: true,
children: [
GetPage(
name: PORTFOLIO,
title: '/portfolio',
page: () => const PortfolioScreen(),
),
// ... other child routes
],
),
];
HomeScreen Implementation:
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Row(
children: [
// Sidebar
Expanded(
child: Column(
children: [
const MyAppBar(),
Expanded(
child: Container(
child: GetRouterOutlet(
anchorRoute: Routes.HOME,
initialRoute: Routes.PORTFOLIO,
key: Get.nestedKey(1),
),
),
),
],
),
),
],
),
);
}
}
Navigation Flow
- App starts at
/login
- After successful authentication, it navigates to
/home
- Inside
/home
, it should show the portfolio screen (/portfolio
) by default - User can navigate between child routes using the sidebar
Debug Output
[GETX] GOING TO ROUTE /home
[GETX] REMOVING ROUTE /login
[GETX] GetDelegate is created !
[GETX] Instance "UserDataController" has been created
[GETX] Instance "UserDataController" has been initialized
What I've Tried
- Verified that all routes are properly defined in the
Routes
class - Confirmed that
initialRoute
is set correctly in bothGetMaterialApp
andGetRouterOutlet
- Checked that the nested key (1) is consistent across the application
- Made sure all controllers are properly initialized through
InitialBinding
Questions
- What could be causing the "Unexpected null value" error in the
GetRouterOutlet
? - Is there something wrong with my nested navigation setup?
Environment
- Flutter: latest stable
- get: ^4.6.5
- firebase_auth: latest
- Platform: Web
Any help would be greatly appreciated!
Thanks again!!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745258431a4619097.html
评论列表(0条)