feat: appmetrica

This commit is contained in:
mso7nueh
2025-08-25 14:24:06 +03:00
parent 886cfa8f1c
commit 5a8fa7089c
7 changed files with 120 additions and 201 deletions

View File

@@ -8,62 +8,61 @@ import 'package:eatvio_app/core/token_storage.dart';
import 'package:eatvio_app/features/registration/models/user_registration_model.dart';
import 'package:eatvio_app/features/registration/presentation/bloc/registration_cubit/registration_state.dart';
import 'package:eatvio_app/features/registration/repositories/registration_repository.dart';
import 'package:eatvio_app/features/registration/services/registration_analytics_service.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class RegistrationCubit extends Cubit<RegistrationState> {
final RegistrationRepository registrationRepository;
RegistrationCubit({
required this.registrationRepository,
}) : super(
const RegistrationState(
sheet: UserRegistrationSheet(
firstName: '',
lastName: '',
email: '',
password: '',
passwordConfirmation: '',
birthdate: '',
gender: '',
location: '',
responseBody: '{}',
lang: 'Русский',
weight: 0,
height: 0,
chestCircumference: 0,
waistCircumference: 0,
hipCircumference: 0,
bloodPressureUp: 0,
bloodPressureDown: 0,
hasHypo: 0,
hasHyper: 0,
aboutAllergy: '',
aboutTakingPils: '',
aboutSportHobbies: '',
favoriteFoods: '',
unfavoriteFoods: '',
additionalInfo: '',
phone: '',
),
RegistrationCubit({required this.registrationRepository})
: super(
const RegistrationState(
sheet: UserRegistrationSheet(
firstName: '',
lastName: '',
email: '',
password: '',
passwordConfirmation: '',
birthdate: '',
gender: '',
location: '',
responseBody: '{}',
lang: 'Русский',
weight: 0,
height: 0,
chestCircumference: 0,
waistCircumference: 0,
hipCircumference: 0,
bloodPressureUp: 0,
bloodPressureDown: 0,
hasHypo: 0,
hasHyper: 0,
aboutAllergy: '',
aboutTakingPils: '',
aboutSportHobbies: '',
favoriteFoods: '',
unfavoriteFoods: '',
additionalInfo: '',
phone: '',
),
);
),
);
void updateSheet(UserRegistrationSheet sheet) => emit(RegistrationState(sheet: sheet));
Future<void> tryRegistration() async {
try {
final token = await registrationRepository.tryRegister(
state.sheet.copyWith(
phone: state.sheet.phone.replaceAll(' ', '').replaceAll('(', '').replaceAll(')', ''),
responseBody: '{}',
),
state.sheet.copyWith(phone: state.sheet.phone.replaceAll(' ', '').replaceAll('(', '').replaceAll(')', ''), responseBody: '{}'),
);
await TokenStorage.saveTokenInStorage(token);
await sl<FirebaseApi>().registerPushToken();
RegistrationAnalyticsService.reportRegistrationComplete();
AppRouter.navigatorKey.currentContext?.replaceNamed('verifyEmailScreen');
} catch (e, st) {
log(e.toString(), stackTrace: st);
RegistrationAnalyticsService.reportRegistrationError(e.toString());
emit(RegistrationState(sheet: state.sheet, error: e.toString()));
}
}

View File

@@ -1,13 +1,12 @@
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
import 'package:eatvio_app/features/registration/presentation/bloc/verify_email_cubit/verify_email_state.dart';
import 'package:eatvio_app/features/registration/services/registration_analytics_service.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class VerifyEmailCubit extends Cubit<VerifyEmailState> {
final ProfileRepository profileRepository;
VerifyEmailCubit({
required this.profileRepository,
}) : super(const VerifyEmailState.loading());
VerifyEmailCubit({required this.profileRepository}) : super(const VerifyEmailState.loading());
Future<void> sendEmailCode() async {
try {
@@ -24,6 +23,7 @@ class VerifyEmailCubit extends Cubit<VerifyEmailState> {
emit(const VerifyEmailState.verifyLoading());
final result = await profileRepository.tryVerifyEmailByCode(code);
if (result == true) {
RegistrationAnalyticsService.reportEmailVerification();
emit(const VerifyEmailState.verifySuccess());
} else {
emit(const VerifyEmailState.verifyError());