new project stable version

This commit is contained in:
2026-05-10 19:11:31 +03:00
commit 3616f84556
391 changed files with 23857 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import 'dart:async';
import 'package:be_happy/domain/usecase/refresh_token_usecase.dart';
import 'package:be_happy/presentation/event/spalsh_event.dart';
import 'package:be_happy/presentation/state/splash_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SplashBloc extends Bloc<SplashEvent, SplashState> {
final RefreshTokenUseCase _refreshTokenUseCase;
SplashBloc(this._refreshTokenUseCase):
super(AuthInitial()) {
on<AuthCheckRequested>(_onAuthCheckRequested);
on<AuthStarted>(_onAuthStarted);
on<PinVerificationSuccess>((event, emit) {
emit(AuthPinVerified());
});
}
Future<void> _onAuthCheckRequested(
AuthCheckRequested event,
Emitter<SplashState> emit,
) async {
print('AuthBloc: Получено событие AuthCheckRequested.');
final prefs = await SharedPreferences.getInstance();
final bool isFirstLaunch = prefs.getBool('is_first_launch') ?? true;
if (isFirstLaunch) {
await prefs.setBool('is_first_launch', false);
emit(AuthFirstLaunch());
return;
}
// 2. Если не первый запуск, пытаемся обновить токен
try {
print('AuthBloc: Пытаюсь обновить токен...');
// Здесь вызывается ваш метод refreshToken()
await _refreshTokenUseCase.execute();
print('AuthBloc: Токен успешно обновлен. Отправляю AuthAuthenticated.');
// Если метод выполнился без исключений, значит токен успешно обновлен
emit(AuthAuthenticated());
} catch (e) {
print('AuthBloc: Ошибка при обновлении токена: $e');
// Если refreshToken() бросил исключение, значит что-то пошло не так
emit(AuthUnauthenticated());
}
}
FutureOr<void> _onAuthStarted(AuthStarted event, Emitter<SplashState> emit) {
emit(AuthInProgress());
}
}