go router

This commit is contained in:
mso7nueh
2024-06-05 12:52:03 +03:00
parent ed0c3fcef1
commit 1951edd8f8
28 changed files with 1160 additions and 1448 deletions

View File

@@ -67,6 +67,7 @@ class _BottomNavigationBarWidgetState extends State<BottomNavigationBarWidget> {
},
selectedFontSize: 12,
unselectedFontSize: 12,
selectedItemColor: appTheme.blueA400,
currentIndex: currentBottomNavBarIndex,
items: [
BottomNavigationBarItem(
@@ -76,18 +77,46 @@ class _BottomNavigationBarWidgetState extends State<BottomNavigationBarWidget> {
BottomNavigationBarItem(
label: 'Лента',
icon: SvgPicture.asset(ImageConstant.imgFeed),
activeIcon: SvgPicture.asset(
ImageConstant.imgFeed,
colorFilter: ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
),
),
),
BottomNavigationBarItem(
label: "diary".tr,
icon: SvgPicture.asset(ImageConstant.imgDiary),
activeIcon: SvgPicture.asset(
ImageConstant.imgDiary,
colorFilter: ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
),
),
),
BottomNavigationBarItem(
label: "chat".tr,
icon: SvgPicture.asset(ImageConstant.imgChat),
activeIcon: SvgPicture.asset(
ImageConstant.imgChat,
colorFilter: ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
),
),
),
BottomNavigationBarItem(
label: '',
icon: SvgPicture.asset(ImageConstant.imgBell),
activeIcon: SvgPicture.asset(
ImageConstant.imgBell,
colorFilter: ColorFilter.mode(
appTheme.blueA400,
BlendMode.srcIn,
),
),
),
BottomNavigationBarItem(
label: '',
@@ -102,223 +131,3 @@ class _BottomNavigationBarWidgetState extends State<BottomNavigationBarWidget> {
);
}
}
// ignore: must_be_immutable
class CustomBottomBar extends StatefulWidget {
CustomBottomBar({this.onChanged});
Function(BottomBarEnum)? onChanged;
@override
CustomBottomBarState createState() => CustomBottomBarState();
}
class CustomBottomBarState extends State<CustomBottomBar> {
int selectedIndex = 2;
List<BottomMenuModel> bottomMenuList = [
BottomMenuModel(
icon: ImageConstant.imgLogo,
activeIcon: ImageConstant.imgLogo,
type: BottomBarEnum.tf,
image: false,
),
BottomMenuModel(
icon: ImageConstant.imgFeed,
activeIcon: ImageConstant.imgFeed,
title: "Лента",
type: BottomBarEnum.tf,
image: false,
),
BottomMenuModel(
icon: ImageConstant.imgDiary,
activeIcon: ImageConstant.imgDiary,
title: "diary".tr,
type: BottomBarEnum.tf,
image: false,
),
BottomMenuModel(
icon: ImageConstant.imgChat,
activeIcon: ImageConstant.imgChat,
title: "chat".tr,
type: BottomBarEnum.tf,
image: false,
),
BottomMenuModel(
icon: ImageConstant.imgBell,
activeIcon: ImageConstant.imgBell,
type: BottomBarEnum.tf,
image: false,
),
BottomMenuModel(
icon: ImageConstant.imgEllipse1,
activeIcon: ImageConstant.imgEllipse1,
type: BottomBarEnum.tf,
image: true,
),
];
@override
Widget build(BuildContext context) {
return Container(
height: 83.v,
decoration: BoxDecoration(
border: Border.all(
color: appTheme.whiteA700,
width: 1.h,
),
),
child: BottomNavigationBar(
backgroundColor: Colors.transparent,
showSelectedLabels: false,
showUnselectedLabels: false,
selectedFontSize: 0,
elevation: 0,
currentIndex: selectedIndex,
type: BottomNavigationBarType.fixed,
items: List.generate(bottomMenuList.length, bottomMenu),
onTap: changeMeny,
),
);
}
void changeMeny(index) {
setState(() {
selectedIndex = index;
});
switch (index) {
case 0:
Navigator.pushReplacementNamed(context, AppRoutes.myProfile);
break;
case 1:
Navigator.pushReplacementNamed(context, AppRoutes.feedScreen);
break;
case 2:
Navigator.pushReplacementNamed(context, AppRoutes.diaryEdit);
break;
case 3:
Navigator.pushReplacementNamed(context, AppRoutes.chatSelectScreen);
break;
}
}
BottomNavigationBarItem bottomMenu(index) {
bool isSelected = selectedIndex == index;
double iconHeight;
double iconWidth;
if (index == 0) {
// Для логотипа-
iconHeight = 52.v; // Увеличиваем высоту
iconWidth = 48.h; // Меняем ширину, чтобы сохранить пропорции
} else if (index == bottomMenuList.length - 2) {
// Для колокольчика
iconHeight = 20.v; // Уменьшаем высоту
iconWidth = 20.h; // Меняем ширину, чтобы сохранить пропорции
} else if (index == bottomMenuList.length - 1) {
// Для колокольчика
iconHeight = 40.v; // Уменьшаем высоту
iconWidth = 40.h; // Меняем ширину, чтобы сохранить пропорции
} else {
// Для остальных иконок
iconHeight = 24.v; // Стандартная высота
iconWidth = 19.h; // Стандартная ширина
}
return BottomNavigationBarItem(
icon: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (!bottomMenuList[index].image)
CustomImageView(
imagePath: bottomMenuList[index].icon,
height: iconHeight,
width: iconWidth,
color: isSelected ? theme.colorScheme.primary : appTheme.blueGray400,
),
if (bottomMenuList[index].image)
GestureDetector(
onTap: () => showMenu(
context: context,
color: Colors.white,
shadowColor: Colors.white,
surfaceTintColor: Colors.white,
position: RelativeRect.fromLTRB(
// Указываем позицию справа по центру
MediaQuery.of(context).size.width - 50, // Расположение от правого края
kToolbarHeight + 340, // Расположение от верхнего края
0, // Не смещаем по горизонтали
0, // Не смещаем по вертикали
),
items: [
PopupMenuItem(
child: CustomNavigationMenu(), // Используйте ваше меню здесь
)
],
),
child: AppbarTitleCircleimage(
imagePath: ImageConstant.imgEllipse1,
),
),
if (bottomMenuList[index].title != null) // Проверяем, существует ли title
Padding(
padding: EdgeInsets.only(top: 8.v),
child: Text(
bottomMenuList[index].title!,
style: CustomTextStyles.bodySmallMulishBluegray80012.copyWith(
color: isSelected ? theme.colorScheme.primary : appTheme.blueGray800,
),
),
),
],
),
activeIcon: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CustomImageView(
imagePath: bottomMenuList[index].activeIcon,
height: iconHeight, // Используем тот же размер для активной иконки
width: iconWidth, // Используем тот же размер для активной иконки
color: theme.colorScheme.primary,
),
Padding(
padding: EdgeInsets.only(top: 9.v),
child: Text(
bottomMenuList[index].title ?? "",
style: CustomTextStyles.bodySmallMulishPrimary.copyWith(
color: theme.colorScheme.primary,
),
),
),
],
),
label: '',
);
}
}
enum BottomBarEnum {
tf,
}
class BottomMenuModel {
BottomMenuModel({
required this.icon,
required this.activeIcon,
this.title,
required this.type,
required this.image,
});
String icon;
String activeIcon;
String? title;
BottomBarEnum type;
bool image;
}

View File

@@ -1,6 +1,7 @@
import 'package:eatvio_app/core/app_export.dart';
import 'package:flutter/material.dart';
import 'package:eatvio_app/widgets/custom_navigation_menu_item.dart';
import 'package:go_router/go_router.dart';
import 'package:hive/hive.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:http/http.dart' as http;
@@ -16,33 +17,30 @@ class CustomNavigationMenu extends StatelessWidget {
MenuItem(
icon: ImageConstant.imgSettings,
text: 'Настройки профиля',
onTap: () => Navigator.pushNamed(context, AppRoutes.mySettings),
onTap: () => GoRouter.of(context).push('/my-settings-screen'),
),
MenuItem(
icon: ImageConstant.imgRecipes,
text: 'Мои рецепты',
onTap: () =>
Navigator.pushNamed(context, AppRoutes.recipeSelectScreen),
onTap: () => GoRouter.of(context).push('/recipe-select-screen'),
// Действие при нажатии на "Мои рецепты"
),
MenuItem(
icon: ImageConstant.imgDiets,
text: 'Мои диеты',
onTap: () =>
Navigator.pushNamed(context, AppRoutes.dietSelectScreen),
onTap: () => GoRouter.of(context).push('/diet-select-screen'),
// Действие при нажатии на "Мои рецепты"
),
MenuItem(
icon: ImageConstant.imgPlans,
text: 'Мои планы',
onTap: () =>
Navigator.pushNamed(context, AppRoutes.planSelectScreen),
onTap: () => GoRouter.of(context).push('/plan-select-screen'),
// Действие при нажатии на "Мои рецепты"
),
MenuItem(
icon: ImageConstant.imgFinance,
text: 'Глоссарий',
onTap: () => Navigator.pushNamed(context, AppRoutes.glossaryScreen),
onTap: () => GoRouter.of(context).push('/glossary-screen'),
),
MenuItem(
icon: ImageConstant.imgSupport,
@@ -77,10 +75,7 @@ _onTapLogout(BuildContext context) {
if (response.statusCode == 204) {
print(response.statusCode);
box.delete('token'); // Удаляем токен из Hive
Navigator.pushNamed(
context,
AppRoutes.authScreen,
);
GoRouter.of(context).go('/auth-screen');
}
};
}