Skip to content

Commit d213969

Browse files
committed
refactor(router): replace prints with logger in router configuration
1 parent 2d0e462 commit d213969

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/router/router.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/settings/view/se
4848
import 'package:flutter_news_app_mobile_client_full_source_code/settings/view/theme_settings_page.dart';
4949
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/feed_decorator_service.dart';
5050
import 'package:go_router/go_router.dart';
51+
import 'package:logging/logging.dart';
5152

5253
/// Creates and configures the GoRouter instance for the application.
5354
///
@@ -76,6 +77,7 @@ GoRouter createRouter({
7677
required AdService adService,
7778
required GlobalKey<NavigatorState> navigatorKey,
7879
required InlineAdCacheService inlineAdCacheService,
80+
required Logger logger,
7981
}) {
8082
// Instantiate FeedDecoratorService once to be shared
8183
final feedDecoratorService = FeedDecoratorService(
@@ -101,7 +103,7 @@ GoRouter createRouter({
101103
final appStatus = context.read<AppBloc>().state.status;
102104
final currentLocation = state.matchedLocation;
103105

104-
print(
106+
logger.info(
105107
'GoRouter Redirect Check:\n'
106108
' Current Location (Matched): $currentLocation\n'
107109
' AppStatus: $appStatus',
@@ -118,24 +120,24 @@ GoRouter createRouter({
118120
// If the user is unauthenticated, they must be on an auth path.
119121
// If they try to go anywhere else, they are redirected to the sign-in page.
120122
if (appStatus == AppLifeCycleStatus.unauthenticated) {
121-
print(' Redirect: User is unauthenticated.');
123+
logger.info(' Redirect: User is unauthenticated.');
122124
return isGoingToAuth ? null : authenticationPath;
123125
}
124126

125127
// --- Case 2: Anonymous User ---
126128
// An anonymous user is partially authenticated. They can browse the app.
127129
if (appStatus == AppLifeCycleStatus.anonymous) {
128-
print(' Redirect: User is anonymous.');
130+
logger.info(' Redirect: User is anonymous.');
129131
// Block anonymous users from the main sign-in page.
130132
if (isGoingToAuth) {
131-
print(
133+
logger.info(
132134
' Action: Anonymous user on auth path. Redirecting to feed.',
133135
);
134136
return feedPath;
135137
}
136138
// If at the root, send them to the feed.
137139
if (currentLocation == rootPath) {
138-
print(' Action: User at root. Redirecting to feed.');
140+
logger.info(' Action: User at root. Redirecting to feed.');
139141
return feedPath;
140142
}
141143
// Allow navigation to other pages, including the new linking page.
@@ -145,23 +147,23 @@ GoRouter createRouter({
145147
// --- Case 3: Authenticated User ---
146148
// A fully authenticated user should be blocked from all auth/linking pages.
147149
if (appStatus == AppLifeCycleStatus.authenticated) {
148-
print(' Redirect: User is authenticated.');
150+
logger.info(' Redirect: User is authenticated.');
149151
if (isGoingToAuth || isGoingToLinking) {
150-
print(
152+
logger.info(
151153
' Action: Authenticated user on auth/linking path. Redirecting to feed.',
152154
);
153155
return feedPath;
154156
}
155157
// If at the root, send them to the feed.
156158
if (currentLocation == rootPath) {
157-
print(' Action: User at root. Redirecting to feed.');
159+
logger.info(' Action: User at root. Redirecting to feed.');
158160
return feedPath;
159161
}
160162
}
161163

162164
// --- Fallback ---
163165
// For any other case (or if no conditions are met), allow navigation.
164-
print(' Redirect: No condition met. Allowing navigation.');
166+
logger.info(' Redirect: No condition met. Allowing navigation.');
165167
return null;
166168
},
167169
// --- Authentication Routes ---
@@ -551,8 +553,8 @@ GoRouter createRouter({
551553
);
552554
} else {
553555
// Handle case where user is unexpectedly null.
554-
print(
555-
'ShellRoute/SettingsBloc: User ID is null when creating SettingsBloc. Settings will not be loaded.',
556+
logger.warning(
557+
'User ID is null when creating SettingsBloc. Settings will not be loaded.',
556558
);
557559
}
558560
return settingsBloc;

0 commit comments

Comments
 (0)