File tree Expand file tree Collapse file tree 4 files changed +23
-6
lines changed Expand file tree Collapse file tree 4 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ class AuthenticationBloc
20
20
super (AuthenticationInitial ()) {
21
21
on < AuthenticationUserChanged > (_onAuthenticationUserChanged);
22
22
on < AuthenticationEmailSignInRequested > (
23
- _onAuthenticationEmailSignInRequested,);
23
+ _onAuthenticationEmailSignInRequested,
24
+ );
24
25
on < AuthenticationGoogleSignInRequested > (
25
26
_onAuthenticationGoogleSignInRequested,
26
27
);
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ class _AuthenticationView extends StatelessWidget {
22
22
23
23
@override
24
24
Widget build (BuildContext context) {
25
- return const Placeholder (child: Text ('AUTHENTICATION PAGE' ),);
25
+ return const Placeholder (
26
+ child: Text ('AUTHENTICATION PAGE' ),
27
+ );
26
28
}
27
29
}
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ class _HeadlinesFeedViewState extends State<_HeadlinesFeedView> {
88
88
IconButton (
89
89
icon: const Icon (Icons .search),
90
90
onPressed: () {
91
- context.pushNamed (Routes .searchName);
91
+ context.goNamed (Routes .searchName);
92
92
},
93
93
),
94
94
BlocBuilder <HeadlinesFeedBloc , HeadlinesFeedState >(
Original file line number Diff line number Diff line change @@ -12,11 +12,25 @@ final appRouter = GoRouter(
12
12
initialLocation: Routes .headlinesFeed,
13
13
redirect: (BuildContext context, GoRouterState state) {
14
14
final appStatus = context.read <AppBloc >().state.status;
15
+ const authenticationPath = Routes .authentication;
16
+ const headlinesFeedPath = Routes .headlinesFeed;
17
+
18
+ // If the user is not authenticated, redirect to the headlines feed
19
+ // unless they are already on a route within the headlines feed.
15
20
if (appStatus != AppStatus .authenticated) {
16
- return Routes .headlinesFeed;
17
- } else {
18
- return Routes .authentication;
21
+ if (! state.matchedLocation.startsWith (headlinesFeedPath)) {
22
+ return headlinesFeedPath;
23
+ }
24
+ }
25
+ // If the user is authenticated, redirect to the authentication page
26
+ // unless they are already on a route within the authentication section.
27
+ else {
28
+ if (! state.matchedLocation.startsWith (authenticationPath)) {
29
+ return authenticationPath;
30
+ }
19
31
}
32
+ // Otherwise, allow the navigation to proceed.
33
+ return null ;
20
34
},
21
35
routes: [
22
36
GoRoute (
You can’t perform that action at this time.
0 commit comments