chats have been updated to work with consultatons

This commit is contained in:
Username1548
2025-03-14 19:56:55 +07:00
parent 9d53760137
commit 803588a289
26 changed files with 957 additions and 281 deletions

View File

@@ -1,10 +1,8 @@
import 'package:eatvio_app/core/app_router.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/token_storage.dart';
import 'package:eatvio_app/core/utils/toasts.dart';
import 'package:eatvio_app/features/auth/presentation/bloc/auth_state.dart';
import 'package:eatvio_app/features/auth/repositories/auth_repository.dart';
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_cubit.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
@@ -15,7 +13,7 @@ class AuthCubit extends Cubit<AuthState> {
required this.authRepository,
}) : super(AuthState());
getTokenByCredentials(String email, String password) async {
Future<bool> getTokenByCredentials(String email, String password) async {
emit(AuthState.loading());
try {
final token = (await authRepository.getTokenByCredentials(
@@ -23,7 +21,6 @@ class AuthCubit extends Cubit<AuthState> {
password,
))
.token;
print(token);
emit(
AuthState.loaded(
token: token,
@@ -31,12 +28,13 @@ class AuthCubit extends Cubit<AuthState> {
);
showSuccessToast('Успешный вход');
await TokenStorage.saveTokenInStorage(token);
await sl<ProfileAvatarCubit>().getMyProfile();
AppRouter.navigatorKey.currentContext?.go('/my-profile-screen');
return true;
} catch (e) {
print(e);
showErrorToast('Неверный адрес электронной почты или пароль');
emit(AuthState.error(errorMessage: '$e'));
return false;
}
}
}

View File

@@ -4,6 +4,8 @@ import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/utils/image_constant.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit.dart';
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_cubit.dart';
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
@@ -140,10 +142,16 @@ class _AuthScreenState extends State<AuthScreen> {
backgroundColor: state is AuthStateLoading ? Colors.black.withAlpha(50) : appTheme.blueA400,
onPressed: state is AuthStateLoading
? null
: () => authCubit.getTokenByCredentials(
: () async {
final isAuthenticated = await authCubit.getTokenByCredentials(
emailController.text,
passwordController.text,
),
);
if (isAuthenticated) {
context.read<ProfileAvatarCubit>().getMyProfile();
context.read<ChatsCubit>().getChatRoomsWithLoading();
}
},
label: state is AuthStateLoading
? CupertinoActivityIndicator()
: Text(