Merge remote-tracking branch 'upstream/main'

This commit is contained in:
Username1548
2025-03-10 22:25:36 +07:00
23 changed files with 294 additions and 204 deletions

View File

@@ -1,6 +1,7 @@
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';
@@ -28,11 +29,13 @@ class AuthCubit extends Cubit<AuthState> {
token: token,
),
);
showSuccessToast('Успешный вход');
await TokenStorage.saveTokenInStorage(token);
await sl<ProfileAvatarCubit>().getMyProfile();
AppRouter.navigatorKey.currentContext?.go('/my-profile-screen');
} catch (e) {
print(e);
showErrorToast('Неверный адрес электронной почты или пароль');
emit(AuthState.error(errorMessage: '$e'));
}
}

View File

@@ -5,6 +5,7 @@ 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/generated/l10n.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';
@@ -12,6 +13,8 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:url_launcher/url_launcher.dart';
import '../bloc/auth_state.dart';
class AuthScreen extends StatefulWidget {
const AuthScreen();
@@ -32,120 +35,128 @@ class _AuthScreenState extends State<AuthScreen> {
FlutterNativeSplash.remove();
return BlocProvider<AuthCubit>(
create: (BuildContext context) => authCubit,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
title: SvgPicture.asset(
ImageConstant.imgLogoEatvio,
height: 48,
fit: BoxFit.contain,
),
),
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(s.email),
const SizedBox(height: 4),
CustomTextFormField(
controller: emailController,
textInputAction: TextInputAction.next,
keyboardType: TextInputType.emailAddress,
textInputType: TextInputType.emailAddress,
hintText: 'Введите email',
),
const SizedBox(height: 16),
Text(s.password),
const SizedBox(height: 4),
CustomTextFormField(
obscureText: hidePassword,
controller: passwordController,
hintText: 'Введите пароль',
suffix: IconButton(
onPressed: () {
setState(() {
hidePassword = !hidePassword;
});
},
icon: Icon(
hidePassword ? Icons.visibility_outlined : Icons.visibility_off_outlined,
color: Colors.grey,
),
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Нет аккаунта? '),
GestureDetector(
onTap: () => GoRouter.of(context).goNamed('webViewRegistrationScreen'),
child: Text(
'Зарегистрироваться',
style: TextStyle(
color: appTheme.blueA400,
decorationColor: appTheme.blueA400,
decoration: TextDecoration.underline,
),
),
),
],
),
Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Нажимая "Войти", Вы соглашаетесь с ',
style: TextStyle(
fontSize: 12,
),
),
GestureDetector(
onTap: () async {
await launchUrl(Uri.parse(baseUrl + '/oferta_bs.pdf'));
},
child: Text(
'Публичной офертой',
style: TextStyle(
fontSize: 12,
color: appTheme.blueA400,
decorationColor: appTheme.blueA400,
decoration: TextDecoration.underline,
),
),
),
],
),
const SizedBox(height: 16),
Container(
height: 48,
width: MediaQuery.of(context).size.width - 32,
child: FloatingActionButton.extended(
heroTag: 'authButton',
highlightElevation: 0,
elevation: 0,
focusElevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
backgroundColor: appTheme.blueA400,
onPressed: () => authCubit.getTokenByCredentials(
emailController.text,
passwordController.text,
),
label: Text(
'Войти',
style: theme.textTheme.titleSmall!.copyWith(color: Colors.white),
),
),
),
],
child: BlocBuilder<AuthCubit, AuthState>(
builder: (BuildContext context, AuthState state) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: SvgPicture.asset(
ImageConstant.imgLogoEatvio,
height: 64,
fit: BoxFit.contain,
),
),
),
),
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(s.email),
const SizedBox(height: 4),
CustomTextFormField(
controller: emailController,
textInputAction: TextInputAction.next,
keyboardType: TextInputType.emailAddress,
textInputType: TextInputType.emailAddress,
hintText: 'Введите email',
),
const SizedBox(height: 16),
Text(s.password),
const SizedBox(height: 4),
CustomTextFormField(
obscureText: hidePassword,
controller: passwordController,
hintText: 'Введите пароль',
suffix: IconButton(
onPressed: () {
setState(() {
hidePassword = !hidePassword;
});
},
icon: Icon(
hidePassword ? Icons.visibility_outlined : Icons.visibility_off_outlined,
color: Colors.grey,
),
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Нет аккаунта? '),
GestureDetector(
onTap: () => GoRouter.of(context).goNamed('webViewRegistrationScreen'),
child: Text(
'Зарегистрироваться',
style: TextStyle(
color: appTheme.blueA400,
decorationColor: appTheme.blueA400,
decoration: TextDecoration.underline,
),
),
),
],
),
Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Нажимая "Войти", Вы соглашаетесь с ',
style: TextStyle(
fontSize: 12,
),
),
GestureDetector(
onTap: () async {
await launchUrl(Uri.parse(baseUrl + '/oferta_bs.pdf'));
},
child: Text(
'Публичной офертой',
style: TextStyle(
fontSize: 12,
color: appTheme.blueA400,
decorationColor: appTheme.blueA400,
decoration: TextDecoration.underline,
),
),
),
],
),
const SizedBox(height: 16),
Container(
height: 48,
width: MediaQuery.of(context).size.width - 32,
child: FloatingActionButton.extended(
heroTag: 'authButton',
highlightElevation: 0,
elevation: 0,
focusElevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
backgroundColor: state is AuthStateLoading ? Colors.black.withAlpha(50) : appTheme.blueA400,
onPressed: state is AuthStateLoading
? null
: () => authCubit.getTokenByCredentials(
emailController.text,
passwordController.text,
),
label: state is AuthStateLoading
? CupertinoActivityIndicator()
: Text(
'Войти',
style: theme.textTheme.titleSmall!.copyWith(color: Colors.white),
),
),
),
],
),
),
),
);
},
),
);
}

View File

@@ -72,7 +72,7 @@ class _CommentsWidgetState extends State<CommentsWidget> {
style: TextStyle(
height: 1,
color: appTheme.gray,
fontSize: 12,
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
@@ -84,7 +84,7 @@ class _CommentsWidgetState extends State<CommentsWidget> {
style: TextStyle(
height: 1,
color: appTheme.black,
fontSize: 12,
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
@@ -97,7 +97,7 @@ class _CommentsWidgetState extends State<CommentsWidget> {
style: TextStyle(
height: 1,
color: appTheme.gray,
fontSize: 12,
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
@@ -112,8 +112,8 @@ class _CommentsWidgetState extends State<CommentsWidget> {
style: TextStyle(
height: 1,
color: appTheme.gray,
fontSize: 12,
fontWeight: FontWeight.w500,
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
),

View File

@@ -102,7 +102,7 @@ class _PlanWidgetState extends State<PlanWidget> {
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
widget.plan.name,
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
style: TextStyles.textMSemibold.copyWith(color: appTheme.black, fontSize: 18),
),
),
if (widget.plan.details.isNotEmpty) ...[
@@ -117,7 +117,7 @@ class _PlanWidgetState extends State<PlanWidget> {
"*": Style(
margin: Margins.zero,
color: appTheme.black,
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
fontSize: FontSize(16),
fontWeight: TextStyles.textSMedium.fontWeight ?? FontWeight.w400,
),
},

View File

@@ -145,7 +145,7 @@ class NoInternetScreen extends StatelessWidget {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Text(
'Проверьте соединение с сетью и попробуйте ещё раз',
'Проверьте соединение с сетью\nи попробуйте ещё раз',
textAlign: TextAlign.center,
style: TextStyles.textMMedium.copyWith(
color: appTheme.gray,

View File

@@ -8,6 +8,7 @@ import 'package:eatvio_app/features/dev_tools/presentation/dev_tools_screen.dart
import 'package:eatvio_app/features/my_diets/presentation/my_diets_screen.dart';
import 'package:eatvio_app/features/my_plans/presentation/my_plans_screen.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
@@ -68,12 +69,12 @@ class MenuScreen extends StatelessWidget {
}
},
),
_divider(context),
_tile(
leading: 'assets/icons/calendar.svg',
title: 'Календарь',
onTap: () => GoRouter.of(context).push('/calendar-screen'),
),
// _divider(context),
// _tile(
// leading: 'assets/icons/calendar.svg',
// title: 'Календарь',
// onTap: () => GoRouter.of(context).push('/calendar-screen'),
// ),
_divider(context),
_tile(
leading: ImageConstant.icnGlossary,
@@ -141,15 +142,36 @@ class MenuScreen extends StatelessWidget {
_onTapLogout(BuildContext context) {
return () async {
try {
await sl<Dio>().post(
baseUrl + '/api/profile/logout',
);
} catch (e) {
} finally {
await TokenStorage.removeTokenInStorage();
GoRouter.of(context).go('/auth-screen', extra: true);
}
showDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text("Выход"),
actions: [
CupertinoDialogAction(
onPressed: () async {
try {
await sl<Dio>().post(
baseUrl + '/api/profile/logout',
);
} catch (e) {
} finally {
await TokenStorage.removeTokenInStorage();
GoRouter.of(context).go('/auth-screen', extra: true);
}
},
child: Text("Выйти"),
isDestructiveAction: true,
),
CupertinoDialogAction(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Отмена"),
),
],
content: Text("Вы уверены что хотите выйти из аккаунта?"),
),
);
};
}
}

View File

@@ -931,7 +931,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
tag: state.profile.profilePhotoUrl,
child: CircleAvatar(
radius: 32,
backgroundImage: NetworkImage(state.profile.profilePhotoUrl),
foregroundImage: NetworkImage(state.profile.profilePhotoUrl),
backgroundImage: AssetImage('assets/images/no_avatar.png'),
),
),
),

View File

@@ -106,6 +106,7 @@ class _ProfileBlogPostWidgetState extends State<ProfileBlogPostWidget> {
state.blogPosts[widget.index].title,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
color: Colors.black87,
),
),
@@ -120,6 +121,7 @@ class _ProfileBlogPostWidgetState extends State<ProfileBlogPostWidget> {
: state.blogPosts[widget.index].description,
style: {
"*": Style(
fontSize: FontSize(16),
color: Colors.black87,
),
},

View File

@@ -1,6 +1,9 @@
import 'dart:convert';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:webview_flutter/webview_flutter.dart';
class WebViewRegistrationScreen extends StatefulWidget {
@@ -12,23 +15,71 @@ class WebViewRegistrationScreen extends StatefulWidget {
class _WebViewRegistrationScreenState extends State<WebViewRegistrationScreen> {
late final WebViewController _controller;
late final AuthCubit authCubit;
String? email;
String? password;
@override
void initState() {
super.initState();
authCubit = sl<AuthCubit>();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..addJavaScriptChannel(
'flutter_inject',
onMessageReceived: (JavaScriptMessage message) {
final data = jsonDecode(message.message);
if (data['type'] == 'email') {
email = data['value'];
print("Email: $email");
} else if (data['type'] == 'password') {
password = data['value'];
print("Password: $password");
}
},
)
..setNavigationDelegate(
NavigationDelegate(
onNavigationRequest: (NavigationRequest request) {
if (request.url.contains('profile')) {
GoRouter.of(context).go('authScreen');
authCubit.getTokenByCredentials(
email!,
password!,
);
}
return NavigationDecision.navigate;
},
),
)
..loadRequest(Uri.parse(baseUrl + '/registration/step1'));
_injectJavaScript();
}
void _injectJavaScript() async {
await Future.delayed(Duration(seconds: 2));
_controller.runJavaScript('''
function sendMessageToFlutter(data) {
window.flutter_inject.postMessage(JSON.stringify(data));
}
function trackInputChanges() {
let emailField = document.getElementById('inputEmail');
let passwordField = document.getElementById('inputPassword');
if (emailField && passwordField) {
emailField.addEventListener('input', function() {
sendMessageToFlutter({ type: 'email', value: emailField.value });
});
passwordField.addEventListener('input', function() {
sendMessageToFlutter({ type: 'password', value: passwordField.value });
});
}
}
trackInputChanges();
''');
}
@override

View File

@@ -420,7 +420,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
title: Text(
title,
style: TextStyle(
fontSize: 14,
fontSize: 16,
fontWeight: FontWeight.w500,
height: 1,
),