feat:增加回到顶部功能

This commit is contained in:
2025-07-24 16:50:50 +08:00
parent 7da3ec9507
commit 502bb9df52
9 changed files with 254 additions and 62 deletions

View File

@@ -40,22 +40,21 @@ class _HomePage extends State<HomePage> {
icon: Icons.account_circle_outlined,
activeIcon: Icons.account_circle,
page: ProfilePage(),
)
),
];
List<BottomNavigationBarItem> get bottomNavItems =>
navItems.map((item) => BottomNavigationBarItem(
icon: Icon(item.icon),
activeIcon: Icon(item.activeIcon),
label: item.label,
)).toList();
navItems
.map(
(item) => BottomNavigationBarItem(
icon: Icon(item.icon),
activeIcon: Icon(item.activeIcon),
label: item.label,
),
)
.toList();
List<Widget> get tabPages =>
navItems.map((item) => item.page).toList();
bool isShow(int index) {
return index == 0 || index == 2;
}
List<Widget> get tabPages => navItems.map((item) => item.page).toList();
@override
Widget build(BuildContext context) {
@@ -64,19 +63,20 @@ class _HomePage extends State<HomePage> {
centerTitle: true,
title: Text('Food Hub', style: TextStyle(color: Colors.white)),
backgroundColor: Theme.of(context).primaryColor,
leading: IconButton(
icon: Icon(Icons.menu, color: Colors.white),
onPressed: () {
// 打开侧边栏或菜单
leading: Builder(
builder: (context) {
return IconButton(
icon: const Icon(Icons.menu),
color: Colors.white,
onPressed: () => Scaffold.of(context).openDrawer(),
);
},
),
actions: homeActions(),
actions: homeActions(context),
),
backgroundColor: Color(0xFFF5F5F5),
endDrawer: const SettingsDrawer(),
drawer: const SettingsDrawer(),
body: tabPages[_currentIndex],
floatingActionButton:
isShow(_currentIndex) ? addItemButton(context) : null,
bottomNavigationBar: NavBar(
navItems: bottomNavItems,
currentIndex: _currentIndex,
@@ -89,17 +89,3 @@ class _HomePage extends State<HomePage> {
);
}
}
Widget addItemButton(BuildContext context) {
void onAddItemClick(BuildContext context) {
Navigator.pushNamed(context, '/recordForm');
}
return FloatingActionButton(
mini: true,
onPressed: () => onAddItemClick(context),
backgroundColor: Theme.of(context).primaryColor,
shape: const CircleBorder(),
child: Icon(Icons.add, color: Colors.white),
);
}