Skip to content

Commit 8ca0f19

Browse files
authored
feat(samples): Show splash while authenticating (#42)
1 parent 0b34d4b commit 8ca0f19

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

sample_app/lib/app/content/auth_controller.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class AuthController extends ValueNotifier<AuthState> {
2323
PushTokenManager? _pushTokenManager;
2424

2525
Future<void> connect(UserCredentials credentials) async {
26+
value = const Authenticating();
27+
2628
final token = UserToken(credentials.token);
2729

2830
final client = StreamFeedsClient(
@@ -83,3 +85,7 @@ final class Authenticated extends AuthState {
8385
final class Unauthenticated extends AuthState {
8486
const Unauthenticated();
8587
}
88+
89+
final class Authenticating extends AuthState {
90+
const Authenticating();
91+
}

sample_app/lib/navigation/app_router.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:stream_feeds/stream_feeds.dart';
77
import '../screens/choose_user/choose_user_screen.dart';
88
import '../screens/home/home_screen.dart';
99
import '../screens/user_feed/user_feed_screen.dart';
10+
import '../widgets/app_splash.dart';
1011
import '../widgets/attachment_gallery/attachment_gallery.dart';
1112
import '../widgets/attachment_gallery/attachment_metadata.dart';
1213
import 'guards/auth_guard.dart';
@@ -45,6 +46,11 @@ class AppRouter extends RootStackRouter {
4546
page: ChooseUserRoute.page,
4647
keepHistory: false,
4748
),
49+
AutoRoute(
50+
path: '/loading',
51+
page: AppSplashRoute.page,
52+
keepHistory: false,
53+
),
4854
AutoRoute(
4955
path: '/attachment_gallery',
5056
page: AttachmentGalleryRoute.page,

sample_app/lib/navigation/app_router.gr.dart

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample_app/lib/navigation/guards/auth_guard.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class AuthGuard extends AutoRouteGuard {
1515
final isAuthenticated = _authController.value is Authenticated;
1616
// If the user is authenticated, allow navigation to the requested route.
1717
if (isAuthenticated) return resolver.next();
18+
19+
// If the user is being authenticated, show the splash screen.
20+
if (_authController.value is Authenticating) {
21+
resolver.redirectUntil(const AppSplashRoute(), replace: true);
22+
}
23+
1824
// Otherwise, redirect to the Choose user page.
1925
resolver.redirectUntil(const ChooseUserRoute(), replace: true);
2026
}

sample_app/lib/widgets/app_splash.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:auto_route/auto_route.dart';
12
import 'package:flutter/material.dart';
23
import 'package:flutter_svg/flutter_svg.dart';
34

@@ -7,6 +8,7 @@ import '../theme/theme.dart';
78
///
89
/// Displays only the app logo in a clean, minimal style while the app initializes.
910
/// Follows true minimalistic principles with perfect simplicity.
11+
@RoutePage(name: 'AppSplashRoute')
1012
class AppSplash extends StatelessWidget {
1113
const AppSplash({super.key});
1214

0 commit comments

Comments
 (0)