Files
eatvio_app/lib/features/menu/presentation/pages/menu_screen.dart
2025-03-14 20:01:39 +07:00

178 lines
5.8 KiB
Dart

import 'package:dio/dio.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/token_storage.dart';
import 'package:eatvio_app/core/utils/image_constant.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
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';
class MenuScreen extends StatelessWidget {
final ProfileModel profileModel;
const MenuScreen({
super.key,
required this.profileModel,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: false,
title: Text('Меню'),
),
body: SingleChildScrollView(
child: Column(
children: [
_tile(
title: 'Настройки профиля',
leading: ImageConstant.icnProfileSettings,
onTap: () => GoRouter.of(context).push('/settings-screen'),
),
if (profileModel.roles.contains('consultant')) _divider(context),
if (profileModel.roles.contains('consultant'))
_tile(
leading: ImageConstant.icnRecipes,
title: 'Мои рецепты',
onTap: () => GoRouter.of(context).push('/recipe-select-screen'),
),
if (profileModel.roles.contains('consultant')) _divider(context),
if (profileModel.roles.contains('consultant'))
_tile(
leading: 'assets/icons/diets.svg',
title: 'Мои диеты',
onTap: () => GoRouter.of(context).push(MyDietsScreen.path),
),
if (profileModel.roles.contains('consultant')) _divider(context),
if (profileModel.roles.contains('consultant'))
_tile(
leading: ImageConstant.icnPlans,
title: 'Мои планы',
onTap: () => GoRouter.of(context).push(MyPlansScreen.path),
),
_divider(context),
_tile(
leading: 'assets/icons/finance.svg',
title: 'Мои финансы',
onTap: () {
if (profileModel.roles.contains('consultant')) {
GoRouter.of(context).pushNamed('consultantFinanceScreen');
} else {
GoRouter.of(context).pushNamed('userFinanceScreen');
}
},
),
// _divider(context),
// _tile(
// leading: 'assets/icons/calendar.svg',
// title: 'Календарь',
// onTap: () => GoRouter.of(context).push('/calendar-screen'),
// ),
_divider(context),
_tile(
leading: ImageConstant.icnGlossary,
title: 'Глоссарий',
onTap: () => GoRouter.of(context).push('/glossary-screen'),
),
_divider(context),
_tile(
leading: ImageConstant.icnSupport,
title: 'Поддержка',
onTap: () => GoRouter.of(context).push('/support-screen'),
),
_divider(context),
_tile(
leading: ImageConstant.icnDevTools,
title: 'Для разработчиков',
onTap: () {
GoRouter.of(context).pushNamed(DevToolsScreen.name);
},
),
_divider(context),
_tile(
leading: ImageConstant.icnExit,
title: 'Выход',
onTap: _onTapLogout(context),
),
],
),
),
);
}
_tile({
required String title,
required String leading,
required Function() onTap,
}) {
return ListTile(
onTap: onTap,
leading: SvgPicture.asset(
leading,
height: 24,
width: 24,
colorFilter: ColorFilter.mode(appTheme.blueA400, BlendMode.srcIn),
),
title: Text(title),
trailing: Icon(
Icons.arrow_forward_ios_rounded,
size: 12,
color: Colors.black38,
),
);
}
_divider(BuildContext context) {
return Container(
height: 0.4,
width: MediaQuery.of(context).size.width - 32,
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(16),
),
);
}
_onTapLogout(BuildContext context) {
return () async {
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("Вы уверены что хотите выйти из аккаунта?"),
),
);
};
}
}