try {
emit(state.copyWith(event: AuthenticationEvents.loginStart));
final loginForm = LoginForm(
emailOrUsername: event.payload.emailOrUsername,
password: event.payload.password,
);
final loginResponse = await _authenticationService.login(loginForm);
// Save token and user if login is successful
if (loginResponse.successResponse != null) {
final token = loginResponse.successResponse!.token;
await _secureStorageCacheService.setToken(token);
// Update token in header
ApiClient.instance.init();
final user = loginResponse.successResponse!.user;
await _secureStorageCacheService.setUser(user);
emit(state.copyWith(
event: AuthenticationEvents.loginSuccess,
authResponse: loginResponse,
));
navigatorKey.currentContext?.read<ProductBloc>().add(ProductEvent.fetchProductStart(payloads: {'tab_type': 'for_you'}));
} else {
emit(state.copyWith(
event: AuthenticationEvents.loginFailure,
authResponse: loginResponse,
));
}
} catch (error, stackTrace) {
CSLog.instance.error(
'Login error occurred',
error: error,
stackTrace: stackTrace,
);
emit(state.copyWith(
event: AuthenticationEvents.loginFailure,
authResponse: AuthResponse(failureResponse: FailureResponse(error: error.toString())),
));
}
}
Hello guys, is this good approach to call productBloc in AuthenticationBloc ?
only if product bloc exist and init in current context
Обсуждают сегодня