We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
notifyListeners() does not force rebuild the Navigator in my modified
import 'package:flutter/material.dart'; import 'package:demo_app/UI/auth/auth.dart'; import 'package:demo_app/UI/splashscreen.dart'; enum ParentRoutes { SplashScreen, Auth, Dashboard, Notification } class ParentRouteConfig { const ParentRouteConfig(this.myRoute, [this.arguments]); final ParentRoutes myRoute; final Object arguments; } class ParentRouteInformationParser extends RouteInformationParser<ParentRouteConfig> { final Map<String, ParentRoutes> _routeStringToEnum = { "/": ParentRoutes.SplashScreen, "/auth": ParentRoutes.Auth, "/dashboard": ParentRoutes.Dashboard, "/notification": ParentRoutes.Notification, }; @override Future<ParentRouteConfig> parseRouteInformation( RouteInformation routeInformation) async { final String routeName = routeInformation.location; // Change to Map final ParentRoutes route = _routeStringToEnum[routeName]; if (route == null) throw Exception("Unknown Route"); return ParentRouteConfig(route, routeInformation.state); } @override RouteInformation restoreRouteInformation(ParentRouteConfig configuration) { switch (configuration.myRoute) { case ParentRoutes.SplashScreen: return RouteInformation(location: '/', state: configuration); case ParentRoutes.Auth: return RouteInformation(location: '/auth', state: configuration); case ParentRoutes.Dashboard: return RouteInformation(location: '/dashboard', state: configuration); case ParentRoutes.Notification: return RouteInformation( location: '/notification', state: configuration); } throw 'unknown'; } } class ParentRouterDelegate extends RouterDelegate<ParentRouteConfig> with ChangeNotifier, PopNavigatorRouterDelegateMixin<ParentRouteConfig> { @override final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>(); final List<Page<void>> _pages = <Page<void>>[ MaterialPage( key: ValueKey("/"), name: "/", child: SplashScreen(), arguments: ParentRouteConfig(ParentRoutes.SplashScreen)), ]; List<Page<void>> pages() => _pages; ParentRouteConfig _currentConfig; set currentConfiguration(ParentRouteConfig config) { if (config != null) _currentConfig = config; notifyListeners(); } @override Future<void> setNewRoutePath(ParentRouteConfig configuration) async { currentConfiguration = configuration; } void addNewPage(ParentRouteConfig configuration) { if (configuration.myRoute == ParentRoutes.Auth) { currentConfiguration = configuration; _pages.add( MaterialPage( key: ValueKey("/auth"), name: "/auth", child: Authentication(currentScreen: (configuration.arguments as int)), arguments: configuration), ); } } // For web application @override ParentRouteConfig get currentConfiguration => _currentConfig; bool _handlePopPage(Route<dynamic> route, dynamic result) { final bool success = route.didPop(result); if (success) { if (_pages.length > 1) { _pages.removeAt(_pages.length - 1); notifyListeners(); } else { navigatorKey.currentState.pop(); } } return success; } @override Widget build(BuildContext context) { return Navigator( key: navigatorKey, pages: pages(), onPopPage: _handlePopPage, ); } }``` I expected to simplify it and it should rebuild on `addNewPage(ParentRouteConfig configuration)`. The pages get added but the UI doesn't render until I use ValueKey Instead of NavigatorKey
The text was updated successfully, but these errors were encountered:
This looks like a bug in framework, can you file a bug in flutter/flutter?
Sorry, something went wrong.
No branches or pull requests
notifyListeners() does not force rebuild the Navigator in my modified
The text was updated successfully, but these errors were encountered: