import 'package:go_router/go_router.dart'; /// Set once in [startApp] so services (e.g. [TokenService.logout]) can navigate /// when [BuildContext] has no [GoRouter] ancestor (e.g. ApiService from MyApp). GoRouter? appGoRouter; void registerAppGoRouter(GoRouter router) { appGoRouter = router; } void navigateAppTo(String location) { final router = appGoRouter; if (router == null) { throw StateError('GoRouter not registered. Call registerAppGoRouter first.'); } router.go(location); }