SchabanBo / qlevar_router

Manage you project Routes. Create nested routes. Simply navigation without context to your pages. Change only one sub widget in your page when navigating to new route.
MIT License
87 stars 22 forks source link

Error: Bad state: No element when trying access child.routeName on builderChild #109

Closed carlosfiori closed 1 year ago

carlosfiori commented 1 year ago

I'm trying to access the route name in builderChild but I'm getting a bad state error.

Stack trace:

Restarted application in 54ms.
QR: Finding Match for /dash under root
QR: adding Route: Key: [0](/dash), Full Path: /dash to the navigator with Key: [-1](Root)
QR: Finding Match for / under path /dash
QR: adding Route: Key: [1](Home Page), Full Path: /dash/ to the navigator with Key: [3](/dash)
Error: Bad state: No element
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 337:5             last]
packages/qlevar_router/src/controllers/qrouter_controller.dart 125:59         get currentRoute
packages/qlevar_router/src/routers/qrouter.dart 26:32                         get routeName
packages/ranked/routes/app_router.dart 11:32                                  <fn>
packages/qlevar_router/src/pages/page_creator.dart 137:21                     build
packages/qlevar_router/src/pages/page_creator.dart 121:51                     create
packages/qlevar_router/src/controllers/pages_controller.dart 23:32            add
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1660:54                                          runUnary
dart-sdk/lib/async/future_impl.dart 147:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 767:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 796:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 567:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 640:7                                     callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
Example code (click to expand): ```dart import 'package:flutter/material.dart'; import 'package:qlevar_router/qlevar_router.dart'; class App extends StatelessWidget { const App({super.key}); @override Widget build(BuildContext context) { return MaterialApp.router( routeInformationParser: const QRouteInformationParser(), routerDelegate: QRouterDelegate( AppRoutes().routes, initPath: '/dash', ), ); } } class AppRoutes { static const String homePage = 'Home Page'; final routes = [ QRoute.withChild( path: '/dash', builderChild: (child) { final routeName = child.routeName; return Scaffold( appBar: AppBar( title: Text(routeName), ), body: child, ); }, children: [ const QRoute( name: homePage, path: '/', builder: HomePage.new, ), ], ), ]; } class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) { return const Center(child: Text('Home')); } } void main() { runApp(const App()); } ```