import 'package:flutter/material.dart'; import 'package:food_hub_app/layout/index.dart'; import 'package:food_hub_app/views/moment.dart'; import 'package:food_hub_app/views/profile.dart'; import 'package:food_hub_app/views/record.dart'; import 'package:food_hub_app/views/stats.dart'; class HomePage extends StatefulWidget { const HomePage({super.key}); @override State createState() => _HomePage(); } class _HomePage extends State { int _currentIndex = 0; final List _tabPages = const [ RecordPage(), StatsPage(), MomentPage(), ProfilePage(), ]; bool isShow(int index) { return index == 0 || index == 2; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( 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: () { // 打开侧边栏或菜单 }, ), actions: homeActions(), ), backgroundColor: Color(0xFFF5F5F5), endDrawer: const SettingsDrawer(), body: _tabPages[_currentIndex], floatingActionButton: isShow(_currentIndex) ? addItemButton(context) : null, bottomNavigationBar: NavBar( currentIndex: _currentIndex, onTap: (index) { setState(() { _currentIndex = index; }); }, ), ); } } 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), ); }