Skip to content

Commit 071d5f2

Browse files
committed
fix: Prevent "Loading Settings" for unauthenticated users
Modified `lib/app/bloc/app_bloc.dart` to correctly initialize the `AppBloc`'s lifecycle status based on the presence of an initial user. This prevents the "Loading Settings" screen from appearing for unauthenticated users before they are directed to the authentication page, ensuring a more accurate and intuitive startup flow.
1 parent 6584a42 commit 071d5f2

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ class AppBloc extends Bloc<AppEvent, AppState> {
5353
_navigatorKey = navigatorKey,
5454
_logger = Logger('AppBloc'),
5555
super(
56-
// Initial state of the app. The status is set to loadingUserData
57-
// as the AppBloc will now handle fetching user-specific data.
58-
// UserAppSettings and UserContentPreferences are initially null
59-
// and will be fetched asynchronously.
6056
AppState(
61-
status: AppLifeCycleStatus.loadingUserData,
57+
status: initialUser == null
58+
? AppLifeCycleStatus.unauthenticated
59+
: AppLifeCycleStatus.loadingUserData,
6260
selectedBottomNavigationIndex: 0,
63-
remoteConfig: initialRemoteConfig, // Use the pre-fetched config
64-
initialRemoteConfigError:
65-
initialRemoteConfigError, // Store any initial config error
61+
remoteConfig: initialRemoteConfig,
62+
initialRemoteConfigError: initialRemoteConfigError,
6663
environment: environment,
67-
user: initialUser, // Set initial user if available
64+
user: initialUser,
6865
),
6966
) {
7067
// Register event handlers for various app-level events.
@@ -262,20 +259,25 @@ class AppBloc extends Bloc<AppEvent, AppState> {
262259
}
263260

264261
// If we reach here, the app is not under maintenance or requires update.
265-
// Proceed to load user-specific data.
266-
emit(state.copyWith(status: AppLifeCycleStatus.loadingUserData));
267-
262+
// Now, handle user-specific data loading.
268263
final currentUser = event.initialUser;
269264

270265
if (currentUser == null) {
271266
_logger.info(
272-
'[AppBloc] No initial user. Transitioning to unauthenticated state.',
267+
'[AppBloc] No initial user. Ensuring unauthenticated state.',
273268
);
274-
emit(state.copyWith(status: AppLifeCycleStatus.unauthenticated));
269+
// Ensure the state is unauthenticated if no user, and it wasn't already set by initial state.
270+
if (state.status != AppLifeCycleStatus.unauthenticated) {
271+
emit(state.copyWith(status: AppLifeCycleStatus.unauthenticated));
272+
}
275273
return;
276274
}
277275

278-
// User is present, proceed to fetch user-specific settings and preferences.
276+
// If a user is present, and we are not already in loadingUserData state,
277+
// transition to loadingUserData and fetch user-specific settings and preferences.
278+
if (state.status != AppLifeCycleStatus.loadingUserData) {
279+
emit(state.copyWith(status: AppLifeCycleStatus.loadingUserData));
280+
}
279281
await _fetchAndSetUserData(currentUser, emit);
280282
}
281283

0 commit comments

Comments
 (0)