post_enrollment_app/lib/router/app_router.dart
2026-05-28 09:54:10 +05:30

18 lines
504 B
Dart

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);
}