Files
eatvio_app/lib/widgets/custom_bottom_bar.dart

222 lines
6.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:eatvio_app/core/app_export.dart';
import 'package:flutter/material.dart';
import 'package:eatvio_app/widgets/app_bar/appbar_title_circleimage.dart';
import 'package:eatvio_app/widgets/custom_navigation_menu.dart';
// 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: 100.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.pushNamed(context, AppRoutes.myProfile);
break;
case 1:
Navigator.pushNamed(context, AppRoutes.feedScreen);
break;
case 2:
Navigator.pushNamed(context, AppRoutes.diaryEdit);
break;
case 3:
Navigator.pushNamed(context, AppRoutes.chatSelectScreen);
break;
}
}
BottomNavigationBarItem bottomMenu(index) {
bool isSelected = selectedIndex == index;
double iconHeight;
double iconWidth;
if (index == 0) {
iconHeight = 50.v;
iconWidth = 50.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;
}